home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / benchmarks / itc / cc1.spur / stmt.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-08-30  |  89.4 KB  |  2,964 lines

  1. /* Expands front end tree to back end RTL for GNU C-Compiler
  2.    Copyright (C) 1987,1988 Free Software Foundation, Inc.
  3.  
  4. This file is part of GNU CC.
  5.  
  6. GNU CC is distributed in the hope that it will be useful,
  7. but WITHOUT ANY WARRANTY.  No author or distributor
  8. accepts responsibility to anyone for the consequences of using it
  9. or for whether it serves any particular purpose or works at all,
  10. unless he says so in writing.  Refer to the GNU CC General Public
  11. License for full details.
  12.  
  13. Everyone is granted permission to copy, modify and redistribute
  14. GNU CC, but only under the conditions described in the
  15. GNU CC General Public License.   A copy of this license is
  16. supposed to have been given to you along with GNU CC so you
  17. can know your rights and responsibilities.  It should be in a
  18. file named COPYING.  Among other things, the copyright notice
  19. and this notice must be preserved on all copies.  */
  20.  
  21.  
  22. /* This file handles the generation of rtl code from tree structure
  23.    above the level of expressions, using subroutines in exp*.c and emit-rtl.c.
  24.    It also creates the rtl expressions for parameters and auto variables
  25.    and has full responsibility for allocating stack slots.
  26.  
  27.    The functions whose names start with `expand_' are called by the
  28.    parser to generate RTL instructions for various kinds of constructs.
  29.  
  30.    Some control and binding constructs require calling several such
  31.    functions at different times.  For example, a simple if-then
  32.    is expanded by calling `expand_start_cond' (with the condition-expression
  33.    as argument) before parsing the then-clause and calling `expand_end_cond'
  34.    after parsing the then-clause.
  35.  
  36.    `expand_start_function' is called at the beginning of a function,
  37.    before the function body is parsed, and `expand_end_function' is
  38.    called after parsing the body.
  39.  
  40.    Call `assign_stack_local' to allocate a stack slot for a local variable.
  41.    This is usually done during the RTL generation for the function body,
  42.    but it can also be done in the reload pass when a pseudo-register does
  43.    not get a hard register.
  44.  
  45.    Call `put_var_into_stack' when you learn, belatedly, that a variable
  46.    previously given a pseudo-register must in fact go in the stack.
  47.    This function changes the DECL_RTL to be a stack slot instead of a reg
  48.    then scans all the RTL instructions so far generated to correct them.  */
  49.  
  50. #include "config.h"
  51.  
  52. #include <stdio.h>
  53.  
  54. #include "rtl.h"
  55. #include "tree.h"
  56. #include "flags.h"
  57. #include "insn-flags.h"
  58. #include "insn-config.h"
  59. #include "expr.h"
  60. #include "regs.h"
  61. #include "alloca.h"
  62.  
  63. #define MAX(x,y) (((x) > (y)) ? (x) : (y))
  64. #define MIN(x,y) (((x) < (y)) ? (x) : (y))
  65.  
  66. /* Nonzero if function being compiled pops its args on return.
  67.    May affect compilation of return insn or of function epilogue.  */
  68.  
  69. int current_function_pops_args;
  70.  
  71. /* If function's args have a fixed size, this is that size, in bytes.
  72.    Otherwise, it is -1.
  73.    May affect compilation of return insn or of function epilogue.  */
  74.  
  75. int current_function_args_size;
  76.  
  77. /* # bytes the prologue should push and pretend that the caller pushed them.
  78.    The prologue must do this, but only if parms can be passed in registers.  */
  79.  
  80. int current_function_pretend_args_size;
  81.  
  82. /* Name of function now being compiled.  */
  83.  
  84. char *current_function_name;
  85.  
  86. /* Label that will go on function epilogue.
  87.    Jumping to this label serves as a "return" instruction
  88.    on machines which require execution of the epilogue on all returns.  */
  89.  
  90. rtx return_label;
  91.  
  92. /* List (chain of EXPR_LISTs) of pseudo-regs of SAVE_EXPRs.
  93.    So we can mark them all live at the end of the function, if nonopt.  */
  94. rtx save_expr_regs;
  95.  
  96. /* Insn after which register parms and SAVE_EXPRs are born, if nonopt.  */
  97. static rtx parm_birth_insn;
  98.  
  99. /* The FUNCTION_DECL node for the function being compiled.  */
  100.  
  101. static tree this_function;
  102.  
  103. /* Offset to end of allocated area of stack frame.
  104.    If stack grows down, this is the address of the last stack slot allocated.
  105.    If stack grows up, this is the address for the next slot.  */
  106. static int frame_offset;
  107.  
  108. /* Nonzero if a stack slot has been generated whose address is not
  109.    actually valid.  It means that the generated rtl must all be scanned
  110.    to detect and correct the invalid addresses where they occur.  */
  111. static int invalid_stack_slot;
  112.  
  113. /* Label to jump back to for tail recursion, or 0 if we have
  114.    not yet needed one for this function.  */
  115. static rtx tail_recursion_label;
  116.  
  117. /* Place after which to insert the tail_recursion_label if we need one.  */
  118. static rtx tail_recursion_reentry;
  119.  
  120. /* Each time we expand an expression-statement,
  121.    record the expr's type and its RTL value here.  */
  122.  
  123. static tree last_expr_type;
  124. static rtx last_expr_value;
  125.  
  126. static void expand_goto_internal ();
  127. static int expand_fixup ();
  128. static void fixup_gotos ();
  129. static int tail_recursion_args ();
  130. void fixup_stack_slots ();
  131. static rtx fixup_stack_1 ();
  132. static rtx fixup_memory_subreg ();
  133. static void fixup_var_refs ();
  134. static rtx fixup_var_refs_1 ();
  135. static rtx parm_stack_loc ();
  136. static void optimize_bit_field ();
  137. void do_jump_if_equal ();
  138.  
  139. /* Stack of control and binding constructs we are currently inside.
  140.  
  141.    These constructs begin when you call `expand_start_WHATEVER'
  142.    and end when you call `expand_end_WHATEVER'.  This stack records
  143.    info about how the construct began that tells the end-function
  144.    what to do.  It also may provide information about the construct
  145.    to alter the behavior of other constructs within the body.
  146.    For example, they may affect the behavior of C `break' and `continue'.
  147.  
  148.    Each construct gets one `struct nesting' object.
  149.    All of these objects are chained through the `all' field.
  150.    `nesting_stack' points to the first object (innermost construct).
  151.    The position of an entry on `nesting_stack' is in its `depth' field.
  152.  
  153.    Each type of construct has its own individual stack.
  154.    For example, loops have `loop_stack'.  Each object points to the
  155.    next object of the same type through the `next' field.
  156.  
  157.    Some constructs are visible to `break' exit-statements and others
  158.    are not.  Which constructs are visible depends on the language.
  159.    Therefore, the data structure allows each construct to be visible
  160.    or not, according to the args given when the construct is started.
  161.    The construct is visible if the `exit_label' field is non-null.
  162.    In that case, the value should be a CODE_LABEL rtx.  */
  163.  
  164. struct nesting
  165. {
  166.   struct nesting *all;
  167.   struct nesting *next;
  168.   int depth;
  169.   rtx exit_label;
  170.   union
  171.     {
  172.       /* For conds (if-then and if-then-else statements).  */
  173.       struct
  174.     {
  175.       /* Label on the else-part, if any, else 0.  */
  176.       rtx else_label;
  177.       /* Label at the end of the whole construct.  */
  178.       rtx after_label;
  179.     } cond;
  180.       /* For loops.  */
  181.       struct
  182.     {
  183.       /* Label at the top of the loop; place to loop back to.  */
  184.       rtx start_label;
  185.       /* Label at the end of the whole construct.  */
  186.       rtx end_label;
  187.       /* Label for `continue' statement to jump to;
  188.          this is in front of the stepper of the loop.  */
  189.       rtx continue_label;
  190.     } loop;
  191.       /* For variable binding contours.  */
  192.       struct
  193.     {
  194.       /* Nonzero => value to restore stack to on exit.  */
  195.       rtx stack_level;
  196.       /* The NOTE that starts this contour.
  197.          Used by expand_goto to check whether the destination
  198.          is within each contour or not.  */
  199.       rtx first_insn;
  200.       /* Innermost containing binding contour that has a stack level.  */
  201.       struct nesting *innermost_stack_block;
  202.       /* Chain of labels defined inside this binding contour.
  203.          Only for contours that have stack levels.  */
  204.       struct label_chain *label_chain;
  205.     } block;
  206.       /* For switch (C) or case (Pascal) statements,
  207.      and also for dummies (see `expand_start_case_dummy').  */
  208.       struct
  209.     {
  210.       /* The insn after which the case dispatch should finally
  211.          be emitted.  Zero for a dummy.  */
  212.       rtx start;
  213.       /* A list of the case-values and their labels.
  214.          A chain of TREE_LIST nodes with the value to test for
  215.          (a constant node) in the TREE_PURPOSE and the
  216.          label (a LABEL_DECL) in the TREE_VALUE.  */
  217.       tree case_list;
  218.       /* The expression to be dispatched on.  */
  219.       tree index_expr;
  220.       /* Type that INDEX_EXPR should be converted to.  */
  221.       tree nominal_type;
  222.     } case_stmt;
  223.     } data;
  224. };
  225.  
  226. /* Chain of all pending binding contours.  */
  227. struct nesting *block_stack;
  228.  
  229. /* Chain of all pending binding contours that restore stack levels.  */
  230. struct nesting *stack_block_stack;
  231.  
  232. /* Chain of all pending conditional statements.  */
  233. struct nesting *cond_stack;
  234.  
  235. /* Chain of all pending loops.  */
  236. struct nesting *loop_stack;
  237.  
  238. /* Chain of all pending case or switch statements.  */
  239. struct nesting *case_stack;
  240.  
  241. /* Separate chain including all of the above,
  242.    chained through the `all' field.  */
  243. struct nesting *nesting_stack;
  244.  
  245. /* Number of entries on nesting_stack now.  */
  246. int nesting_depth;
  247.  
  248. /* Pop one of the sub-stacks, such as `loop_stack' or `cond_stack';
  249.    and pop off `nesting_stack' down to the same level.  */
  250.  
  251. #define POPSTACK(STACK)                    \
  252. do { int initial_depth = nesting_stack->depth;        \
  253.      do { struct nesting *this = STACK;            \
  254.       STACK = this->next;                \
  255.       nesting_stack = this->all;            \
  256.       nesting_depth = this->depth;            \
  257.       free (this); }                \
  258.      while (nesting_depth > initial_depth); } while (0)
  259.  
  260. /* Return the rtx-label that corresponds to a LABEL_DECL,
  261.    creating it if necessary.  */
  262.  
  263. static rtx
  264. label_rtx (label)
  265.      tree label;
  266. {
  267.   if (TREE_CODE (label) != LABEL_DECL)
  268.     abort ();
  269.  
  270.   if (DECL_RTL (label))
  271.     return DECL_RTL (label);
  272.  
  273.   return DECL_RTL (label) = gen_label_rtx ();
  274. }
  275.  
  276. /* Add an unconditional jump to LABEL as the next sequential instruction.  */
  277.  
  278. void
  279. emit_jump (label)
  280.      rtx label;
  281. {
  282.   do_pending_stack_adjust ();
  283.   emit_jump_insn (gen_jump (label));
  284.   emit_barrier ();
  285. }
  286.  
  287. /* Handle goto statements and the labels that they can go to.  */
  288.  
  289. /* In some cases it is impossible to generate code for a forward goto 
  290.    until the label definition is seen.  This happens when it may be necessary
  291.    for the goto to reset the stack pointer: we don't yet know how to do that.
  292.    So expand_goto puts an entry on this fixup list.
  293.    Each time a binding contour that resets the stack is exited,
  294.    we check each fixup.
  295.    If the target label has now been defined, we can insert the proper code.  */
  296.  
  297. struct goto_fixup
  298. {
  299.   /* Points to following fixup.  */
  300.   struct goto_fixup *next;
  301.   /* Points to the insn before the jump insn.
  302.      If more code must be inserted, it goes after this insn.  */
  303.   rtx before_jump;
  304.   /* The LABEL_DECL that this jump is jumping to, or 0
  305.      for break, continue or return.  */
  306.   tree target;
  307.   /* The CODE_LABEL rtx that this is jumping to.  */
  308.   rtx target_rtl;
  309.   /* The outermost stack level that should be restored for this jump.
  310.      Each time a binding contour that resets the stack is exited,
  311.      if the target label is *not* yet defined, this slot is updated.  */
  312.   rtx stack_level;
  313. };
  314.  
  315. static struct goto_fixup *goto_fixup_chain;
  316.  
  317. /* Within any binding contour that must restore a stack level,
  318.    all labels are recorded with a chain of these structures.  */
  319.  
  320. struct label_chain
  321. {
  322.   /* Points to following fixup.  */
  323.   struct label_chain *next;
  324.   tree label;
  325. };
  326.  
  327. /* Specify the location in the RTL code of a label BODY,
  328.    which is a LABEL_DECL tree node.
  329.  
  330.    This is used for the kind of label that the user can jump to with a
  331.    goto statement, and for alternatives of a switch or case statement.
  332.    RTL labels generated for loops and conditionals don't go through here;
  333.    they are generated directly at the RTL level, by other functions below.
  334.  
  335.    Note that this has nothing to do with defining label *names*.
  336.    Languages vary in how they do that and what that even means.  */
  337.  
  338. void
  339. expand_label (body)
  340.      tree body;
  341. {
  342.   struct label_chain *p;
  343.  
  344.   do_pending_stack_adjust ();
  345.   emit_label (label_rtx (body));
  346.  
  347.   if (stack_block_stack)
  348.     {
  349.       p = (struct label_chain *) oballoc (sizeof (struct label_chain));
  350.       p->next = stack_block_stack->data.block.label_chain;
  351.       stack_block_stack->data.block.label_chain = p;
  352.       p->label = body;
  353.     }
  354. }
  355.  
  356. /* Generate RTL code for a `goto' statement with target label BODY.
  357.    BODY should be a LABEL_DECL tree node that was or will later be
  358.    defined with `expand_label'.  */
  359.  
  360. void
  361. expand_goto (body)
  362.      tree body;
  363. {
  364.   expand_goto_internal (body, label_rtx (body));
  365. }
  366.  
  367. static void
  368. expand_goto_internal (body, label)
  369.      tree body;
  370.      rtx label;
  371. {
  372.   struct nesting *block;
  373.   rtx stack_level = 0;
  374.  
  375.   if (GET_CODE (label) != CODE_LABEL)
  376.     abort ();
  377.  
  378.   /* If label has already been defined, we can tell now
  379.      whether and how we must alter the stack level.  */
  380.  
  381.   if (PREV_INSN (label) != 0)
  382.     {
  383.       /* Find the outermost pending block that contains the label.
  384.      (Check containment by comparing insn-uids.)
  385.      Then restore the outermost stack level within that block.  */
  386.       for (block = block_stack; block; block = block->next)
  387.     {
  388.       if (INSN_UID (block->data.block.first_insn) < INSN_UID (label))
  389.         break;
  390.       if (block->data.block.stack_level != 0)
  391.         stack_level = block->data.block.stack_level;
  392.     }
  393.  
  394.       if (stack_level)
  395.     emit_move_insn (stack_pointer_rtx, stack_level);
  396.  
  397.       if (body != 0 && TREE_PACKED (body))
  398.     error ("goto \"%s\" invalidly jumps into binding contour",
  399.            IDENTIFIER_POINTER (DECL_NAME (body)));
  400.     }
  401.   /* Label not yet defined: may need to put this goto
  402.      on the fixup list.  */
  403.   else if (! expand_fixup (body, label))
  404.     /* No fixup needed.  Record that the label is the target
  405.        of at least one goto that has no fixup.  */
  406.     if (body != 0)
  407.       TREE_ADDRESSABLE (body) = 1;
  408.  
  409.   emit_jump (label);
  410. }
  411.  
  412. /* Generate if necessary a fixup for a goto
  413.    whose target label in tree structure (if any) is TREE_LABEL
  414.    and whose target in rtl is RTL_LABEL.
  415.  
  416.    The fixup will be used later to insert insns at this point
  417.    to restore the stack level as appropriate for the target label.
  418.  
  419.    Value is nonzero if a fixup is made.  */
  420.  
  421. static int
  422. expand_fixup (tree_label, rtl_label)
  423.      tree tree_label;
  424.      rtx rtl_label;
  425. {
  426.   struct nesting *block;
  427.   /* Does any containing block have a stack level?
  428.      If not, no fixup is needed, and that is the normal case
  429.      (the only case, for standard C).  */
  430.   for (block = block_stack; block; block = block->next)
  431.     if (block->data.block.stack_level != 0)
  432.       break;
  433.  
  434.   if (block)
  435.     {
  436.       /* Ok, a fixup is needed.  Add a fixup to the list of such.  */
  437.       struct goto_fixup *fixup
  438.     = (struct goto_fixup *) oballoc (sizeof (struct goto_fixup));
  439.       /* In case an old stack level is restored, make sure that comes
  440.      after any pending stack adjust.  */
  441.       do_pending_stack_adjust ();
  442.       fixup->before_jump = get_last_insn ();
  443.       fixup->target = tree_label;
  444.       fixup->target_rtl = rtl_label;
  445.       fixup->stack_level = 0;
  446.       fixup->next = goto_fixup_chain;
  447.       goto_fixup_chain = fixup;
  448.     }
  449.  
  450.   return block != 0;
  451. }
  452.  
  453. /* When exiting a binding contour, process all pending gotos requiring fixups.
  454.    STACK_LEVEL is the rtx for the stack level to restore on exit from
  455.    this contour.  FIRST_INSN is the insn that begain this contour.
  456.    Gotos that jump out of this contour must restore the
  457.    stack level before actually jumping.
  458.  
  459.    Also print an error message if any fixup describes a jump into this
  460.    contour from before the beginning of the contour.  */
  461.  
  462. static void
  463. fixup_gotos (stack_level, first_insn)
  464.      rtx stack_level;
  465.      rtx first_insn;
  466. {
  467.   register struct goto_fixup *f;
  468.  
  469.   for (f = goto_fixup_chain; f; f = f->next)
  470.     {
  471.       /* Test for a fixup that is inactive because it is already handled.  */
  472.       if (f->before_jump == 0)
  473.     ;
  474.       /* Has this fixup's target label been defined?
  475.      If so, we can finalize it.  */
  476.       else if (PREV_INSN (f->target_rtl) != 0)
  477.     {
  478.       /* If this fixup jumped into this contour from before the beginning
  479.          of this contour, report an error.  */
  480.       if (f->target != 0
  481.           && INSN_UID (first_insn) > INSN_UID (f->before_jump)
  482.           && ! TREE_ADDRESSABLE (f->target))
  483.         {
  484.           error_with_file_and_line (DECL_SOURCE_FILE (f->target),
  485.                     DECL_SOURCE_LINE (f->target),
  486.                     "label \"%s\" was used \
  487. before containing binding contour",
  488.                     IDENTIFIER_POINTER (DECL_NAME (f->target)));
  489.           /* Prevent multiple errors for one label.  */
  490.           TREE_ADDRESSABLE (f->target) = 1;
  491.         }
  492.  
  493.       /* Restore stack level for the biggest contour that this
  494.          jump jumps out of.  */
  495.       if (f->stack_level)
  496.         emit_insn_after (gen_move_insn (stack_pointer_rtx, f->stack_level),
  497.                  f->before_jump);
  498.       f->before_jump = 0;
  499.     }
  500.       /* Label has still not appeared.  If we are exiting a block with
  501.      a stack level to restore, mark this stack level as needing
  502.      restoration when the fixup is later finalized.  */
  503.       else if (stack_level)
  504.     f->stack_level = stack_level;
  505.     }
  506. }
  507.  
  508. /* Generate RTL for an asm statement (explicit assembler code).
  509.    BODY is a STRING_CST node containing the assembler code text.  */
  510.  
  511. void
  512. expand_asm (body)
  513.      tree body;
  514. {
  515.   emit_insn (gen_rtx (ASM_INPUT, VOIDmode,
  516.               TREE_STRING_POINTER (body)));
  517.   last_expr_type = 0;
  518. }
  519.  
  520. /* Generate RTL for an asm statement with arguments.
  521.    STRING is the instruction template.
  522.    OUTPUTS is a list of output arguments (lvalues); INPUTS a list of inputs.
  523.    Each output or input has an expression in the TREE_VALUE and
  524.    a constraint-string in the TREE_PURPOSE.
  525.  
  526.    Not all kinds of lvalue that may appear in OUTPUTS can be stored directly.
  527.    Some elements of OUTPUTS may be replaced with trees representing temporary
  528.    values.  The caller should copy those temporary values to the originally
  529.    specified lvalues.
  530.  
  531.    VOL nonzero means the insn is volatile; don't optimize it.  */
  532.  
  533. void
  534. expand_asm_operands (string, outputs, inputs, vol)
  535.      tree string, outputs, inputs;
  536.      int vol;
  537. {
  538.   rtvec argvec, constraints;
  539.   rtx body;
  540.   int ninputs = list_length (inputs);
  541.   int noutputs = list_length (outputs);
  542.   int numargs = 0;
  543.   tree tail;
  544.   int i;
  545.  
  546.   last_expr_type = 0;
  547.  
  548.   if (ninputs + noutputs > MAX_RECOG_OPERANDS)
  549.     {
  550.       error ("more than %d operands in `asm'", MAX_RECOG_OPERANDS);
  551.       return;
  552.     }
  553.  
  554.   for (i = 0, tail = outputs; tail; tail = TREE_CHAIN (tail), i++)
  555.     {
  556.       tree val = TREE_VALUE (tail);
  557.  
  558.       /* If there's an erroneous arg, emit no insn.  */
  559.       if (TREE_TYPE (val) == error_mark_node)
  560.     return;
  561.  
  562.       /* If an output operand is not a variable or indirect ref,
  563.      create a SAVE_EXPR which is a pseudo-reg
  564.      to act as an intermediate temporary.
  565.      Make the asm insn write into that, then copy it to
  566.      the real output operand.  */
  567.  
  568.       if (TREE_CODE (val) != VAR_DECL
  569.       && TREE_CODE (val) != PARM_DECL
  570.       && TREE_CODE (val) != INDIRECT_REF)
  571.     TREE_VALUE (tail) = build (SAVE_EXPR, TREE_TYPE (val), val,
  572.                    gen_reg_rtx (TYPE_MODE (TREE_TYPE (val))));
  573.     }
  574.  
  575.   /* Make vectors for the expression-rtx and constraint strings.  */
  576.  
  577.   argvec = rtvec_alloc (ninputs);
  578.   constraints = rtvec_alloc (ninputs);
  579.  
  580.   body = gen_rtx (ASM_OPERANDS, VOIDmode,
  581.           TREE_STRING_POINTER (string), "", 0, argvec, constraints);
  582.   body->volatil = vol;
  583.  
  584.   /* Eval the inputs and put them into ARGVEC.
  585.      Put their constraints into ASM_INPUTs and store in CONSTRAINTS.  */
  586.  
  587.   i = 0;
  588.   for (tail = inputs; tail; tail = TREE_CHAIN (tail))
  589.     {
  590.       /* If there's an erroneous arg, emit no insn,
  591.      because the ASM_INPUT would get VOIDmode
  592.      and that could cause a crash in reload.  */
  593.       if (TREE_TYPE (TREE_VALUE (tail)) == error_mark_node)
  594.     return;
  595.  
  596.       XVECEXP (body, 3, i)      /* argvec */
  597.     = expand_expr (TREE_VALUE (tail), 0, VOIDmode, 0);
  598.       XVECEXP (body, 4, i)      /* constraints */
  599.     = gen_rtx (ASM_INPUT, TYPE_MODE (TREE_TYPE (TREE_VALUE (tail))),
  600.            TREE_STRING_POINTER (TREE_PURPOSE (tail)));
  601.       i++;
  602.     }
  603.  
  604.   /* Now, for each output, construct an rtx
  605.      (set OUTPUT (asm_operands INSN OUTPUTNUMBER OUTPUTCONSTRAINT
  606.                    ARGVEC CONSTRAINTS))
  607.      If there is more than one, put them inside a PARALLEL.  */
  608.  
  609.   if (noutputs == 1)
  610.     {
  611.       tree val = TREE_VALUE (outputs);
  612.  
  613.       XSTR (body, 1) = TREE_STRING_POINTER (TREE_PURPOSE (outputs));
  614.       emit_insn (gen_rtx (SET, VOIDmode,
  615.               expand_expr (val, 0, VOIDmode, 0),
  616.               body));
  617.     }
  618.   else if (noutputs == 0)
  619.     {
  620.       /* No output operands: put in a raw ASM_OPERANDS rtx.  */
  621.       emit_insn (body);
  622.     }
  623.   else
  624.     {
  625.       body = gen_rtx (PARALLEL, VOIDmode, rtvec_alloc (noutputs));
  626.  
  627.       for (i = 0, tail = outputs; tail; tail = TREE_CHAIN (tail), i++)
  628.     {
  629.       tree val = TREE_VALUE (tail);
  630.  
  631.       XVECEXP (body, 0, i)
  632.         = gen_rtx (SET, VOIDmode,
  633.                expand_expr (val, 0, VOIDmode, 0),
  634.                gen_rtx (ASM_OPERANDS, VOIDmode,
  635.                 TREE_STRING_POINTER (string),
  636.                 TREE_STRING_POINTER (TREE_PURPOSE (tail)),
  637.                 i, argvec, constraints));
  638.       SET_SRC (XVECEXP (body, 0, i))->volatil = vol;
  639.     }
  640.  
  641.       emit_insn (body);
  642.     }
  643.   last_expr_type = 0;
  644. }
  645.  
  646. /* Nonzero if within a ({...}) grouping, in which case we must
  647.    always compute a value for each expr-stmt in case it is the last one.  */
  648.  
  649. int expr_stmts_for_value;
  650.  
  651. /* Generate RTL to evaluate the expression EXP
  652.    and remember it in case this is the VALUE in a ({... VALUE; }) constr.  */
  653.  
  654. void
  655. expand_expr_stmt (exp)
  656.      tree exp;
  657. {
  658.   last_expr_type = TREE_TYPE (exp);
  659.   last_expr_value = expand_expr (exp, expr_stmts_for_value ? 0 : const0_rtx,
  660.                  VOIDmode, 0);
  661.   emit_queue ();
  662. }
  663.  
  664. /* Clear out the memory of the last expression evaluated.  */
  665.  
  666. void
  667. clear_last_expr ()
  668. {
  669.   last_expr_type = 0;
  670. }
  671.  
  672. /* Return a tree node that refers to the last expression evaluated.
  673.    The nodes of that expression have been freed by now, so we cannot use them.
  674.    But we don't want to do that anyway; the expression has already been
  675.    evaluated and now we just want to use the value.  So generate a SAVE_EXPR
  676.    with the proper type and RTL value.
  677.  
  678.    If the last statement was not an expression,
  679.    return something with type `void'.  */
  680.  
  681. tree
  682. get_last_expr ()
  683. {
  684.   tree t;
  685.  
  686.   if (last_expr_type == 0)
  687.     {
  688.       last_expr_type = void_type_node;
  689.       last_expr_value = const0_rtx;
  690.     }
  691.   t = build (RTL_EXPR, last_expr_type, NULL, NULL);
  692.   RTL_EXPR_RTL (t) = last_expr_value;
  693.   RTL_EXPR_SEQUENCE (t) = gen_sequence ();
  694.   return t;
  695. }
  696.  
  697. void
  698. expand_start_stmt_expr ()
  699. {
  700.   extern int emit_to_sequence;
  701.   expr_stmts_for_value++;
  702.   emit_to_sequence++;
  703. }
  704.  
  705. void
  706. expand_end_stmt_expr ()
  707. {
  708.   extern int emit_to_sequence;
  709.   expr_stmts_for_value--;
  710.   emit_to_sequence--;
  711. }
  712.  
  713. /* Generate RTL for the start of an if-then.  COND is the expression
  714.    whose truth should be tested.
  715.  
  716.    If EXITFLAG is nonzero, this conditional is visible to
  717.    `exit_something'.  */
  718.  
  719. void
  720. expand_start_cond (cond, exitflag)
  721.      tree cond;
  722.      int exitflag;
  723. {
  724.   struct nesting *thiscond
  725.     = (struct nesting *) xmalloc (sizeof (struct nesting));
  726.  
  727.   /* Make an entry on cond_stack for the cond we are entering.  */
  728.  
  729.   thiscond->next = cond_stack;
  730.   thiscond->all = nesting_stack;
  731.   thiscond->depth = ++nesting_depth;
  732.   thiscond->data.cond.after_label = 0;
  733.   thiscond->data.cond.else_label = gen_label_rtx ();
  734.   thiscond->exit_label = exitflag ? thiscond->data.cond.else_label : 0;
  735.   cond_stack = thiscond;
  736.   nesting_stack = thiscond;
  737.  
  738.   do_jump (cond, thiscond->data.cond.else_label, NULL);
  739. }
  740.  
  741. /* Generate RTL for the end of an if-then with no else-clause.
  742.    Pop the record for it off of cond_stack.  */
  743.  
  744. void
  745. expand_end_cond ()
  746. {
  747.   struct nesting *thiscond = cond_stack;
  748.  
  749.   do_pending_stack_adjust ();
  750.   emit_label (thiscond->data.cond.else_label);
  751.  
  752.   POPSTACK (cond_stack);
  753.   last_expr_type = 0;
  754. }
  755.  
  756. /* Generate RTL between the then-clause and the else-clause
  757.    of an if-then-else.  */
  758.  
  759. void
  760. expand_start_else ()
  761. {
  762.   cond_stack->data.cond.after_label = gen_label_rtx ();
  763.   if (cond_stack->exit_label != 0)
  764.     cond_stack->exit_label = cond_stack->data.cond.after_label;
  765.   emit_jump (cond_stack->data.cond.after_label);
  766.   if (cond_stack->data.cond.else_label)
  767.     emit_label (cond_stack->data.cond.else_label);
  768. }
  769.  
  770. /* Generate RTL for the end of an if-then-else.
  771.    Pop the record for it off of cond_stack.  */
  772.  
  773. void
  774. expand_end_else ()
  775. {
  776.   struct nesting *thiscond = cond_stack;
  777.  
  778.   do_pending_stack_adjust ();
  779.   /* Note: a syntax error can cause this to be called
  780.      without first calling `expand_start_else'.  */
  781.   if (thiscond->data.cond.after_label)
  782.     emit_label (thiscond->data.cond.after_label);
  783.  
  784.   POPSTACK (cond_stack);
  785.   last_expr_type = 0;
  786. }
  787.  
  788. /* Generate RTL for the start of a loop.  EXIT_FLAG is nonzero if this
  789.    loop should be exited by `exit_something'.  This is a loop for which
  790.    `expand_continue' will jump to the top of the loop.
  791.  
  792.    Make an entry on loop_stack to record the labels associated with
  793.    this loop.  */
  794.  
  795. void
  796. expand_start_loop (exit_flag)
  797.      int exit_flag;
  798. {
  799.   register struct nesting *thisloop
  800.     = (struct nesting *) xmalloc (sizeof (struct nesting));
  801.  
  802.   /* Make an entry on loop_stack for the loop we are entering.  */
  803.  
  804.   thisloop->next = loop_stack;
  805.   thisloop->all = nesting_stack;
  806.   thisloop->depth = ++nesting_depth;
  807.   thisloop->data.loop.start_label = gen_label_rtx ();
  808.   thisloop->data.loop.end_label = gen_label_rtx ();
  809.   thisloop->data.loop.continue_label = thisloop->data.loop.start_label;
  810.   thisloop->exit_label = exit_flag ? thisloop->data.loop.end_label : 0;
  811.   loop_stack = thisloop;
  812.   nesting_stack = thisloop;
  813.  
  814.   do_pending_stack_adjust ();
  815.   emit_queue ();
  816.   emit_note (0, NOTE_INSN_LOOP_BEG);
  817.   emit_label (thisloop->data.loop.start_label);
  818. }
  819.  
  820. /* Like expand_start_loop but for a loop where the continuation point
  821.    (for expand_continue_loop) will be specified explicitly.  */
  822.  
  823. void
  824. expand_start_loop_continue_elsewhere (exit_flag)
  825.      int exit_flag;
  826. {
  827.   expand_start_loop (exit_flag);
  828.   loop_stack->data.loop.continue_label = gen_label_rtx ();
  829. }
  830.  
  831. /* Specify the continuation point for a loop started with
  832.    expand_start_loop_continue_elsewhere.
  833.    Use this at the point in the code to which a continue statement
  834.    should jump.  */
  835.  
  836. void
  837. expand_loop_continue_here ()
  838. {
  839.   do_pending_stack_adjust ();
  840.   emit_label (loop_stack->data.loop.continue_label);
  841. }
  842.  
  843. /* Finish a loop.  Generate a jump back to the top and the loop-exit label.
  844.    Pop the block off of loop_stack.  */
  845.  
  846. void
  847. expand_end_loop ()
  848. {
  849.   register struct nesting *thisloop = loop_stack;
  850.   register rtx insn = get_last_insn ();
  851.   register rtx start_label = loop_stack->data.loop.start_label;
  852.  
  853.   do_pending_stack_adjust ();
  854.  
  855.   /* If optimizing, perhaps reorder the loop.  If the loop
  856.      starts with a conditional exit, roll that to the end
  857.      where it will optimize together with the jump back.  */
  858.   if (optimize
  859.       &&
  860.       ! (GET_CODE (insn) == JUMP_INSN
  861.      && GET_CODE (PATTERN (insn)) == SET
  862.      && SET_DEST (PATTERN (insn)) == pc_rtx
  863.      && GET_CODE (SET_SRC (PATTERN (insn))) == IF_THEN_ELSE))
  864.     {
  865.       /* Scan insns from the top of the loop looking for a qualified
  866.      conditional exit.  */
  867.       for (insn = loop_stack->data.loop.start_label; insn; insn= NEXT_INSN (insn))
  868.     if (GET_CODE (insn) == JUMP_INSN && GET_CODE (PATTERN (insn)) == SET
  869.         && SET_DEST (PATTERN (insn)) == pc_rtx
  870.         && GET_CODE (SET_SRC (PATTERN (insn))) == IF_THEN_ELSE
  871.         &&
  872.         ((GET_CODE (XEXP (SET_SRC (PATTERN (insn)), 1)) == LABEL_REF
  873.           && (XEXP (XEXP (SET_SRC (PATTERN (insn)), 1), 0)
  874.           == loop_stack->data.loop.end_label))
  875.          ||
  876.          (GET_CODE (XEXP (SET_SRC (PATTERN (insn)), 2)) == LABEL_REF
  877.           && (XEXP (XEXP (SET_SRC (PATTERN (insn)), 2), 0)
  878.           == loop_stack->data.loop.end_label))))
  879.       break;
  880.       if (insn != 0)
  881.     {
  882.       /* We found one.  Move everything from there up
  883.          to the end of the loop, and add a jump into the loop
  884.          to jump to there.  */
  885.       register rtx newstart_label = gen_label_rtx ();
  886.  
  887.       emit_label_after (newstart_label, PREV_INSN (start_label));
  888.       reorder_insns (start_label, insn, get_last_insn ());
  889.       emit_jump_insn_after (gen_jump (start_label), PREV_INSN (newstart_label));
  890.       emit_barrier_after (PREV_INSN (newstart_label));
  891.       start_label = newstart_label;
  892.     }
  893.     }
  894.  
  895.   emit_jump (start_label);
  896.   emit_note (0, NOTE_INSN_LOOP_END);
  897.   emit_label (loop_stack->data.loop.end_label);
  898.  
  899.   POPSTACK (loop_stack);
  900.  
  901.   last_expr_type = 0;
  902. }
  903.  
  904. /* Generate a jump to the current loop's continue-point.
  905.    This is usually the top of the loop, but may be specified
  906.    explicitly elsewhere.  If not currently inside a loop,
  907.    return 0 and do nothing; caller will print an error message.  */
  908.  
  909. int
  910. expand_continue_loop ()
  911. {
  912.   last_expr_type = 0;
  913.   if (loop_stack == 0)
  914.     return 0;
  915.   expand_goto_internal (0, loop_stack->data.loop.continue_label);
  916.   return 1;
  917. }
  918.  
  919. /* Generate a jump to exit the current loop.  If not currently inside a loop,
  920.    return 0 and do nothing; caller will print an error message.  */
  921.  
  922. int
  923. expand_exit_loop ()
  924. {
  925.   last_expr_type = 0;
  926.   if (loop_stack == 0)
  927.     return 0;
  928.   expand_goto_internal (0, loop_stack->data.loop.end_label);
  929.   return 1;
  930. }
  931.  
  932. /* Generate a conditional jump to exit the current loop if COND
  933.    evaluates to zero.  If not currently inside a loop,
  934.    return 0 and do nothing; caller will print an error message.  */
  935.  
  936. int
  937. expand_exit_loop_if_false (cond)
  938.      tree cond;
  939. {
  940.   last_expr_type = 0;
  941.   if (loop_stack == 0)
  942.     return 0;
  943.   do_jump (cond, loop_stack->data.loop.end_label, NULL);
  944.   return 1;
  945. }
  946.  
  947. /* Generate a jump to exit the current loop, conditional, binding contour
  948.    or case statement.  Not all such constructs are visible to this function,
  949.    only those started with EXIT_FLAG nonzero.  Individual languages use
  950.    the EXIT_FLAG parameter to control which kinds of constructs you can
  951.    exit this way.
  952.  
  953.    If not currently inside anything that can be exited,
  954.    return 0 and do nothing; caller will print an error message.  */
  955.  
  956. int
  957. expand_exit_something ()
  958. {
  959.   struct nesting *n;
  960.   last_expr_type = 0;
  961.   for (n = nesting_stack; n; n = n->all)
  962.     {
  963.       if (n->exit_label != 0)
  964.     {
  965.       expand_goto_internal (0, n->exit_label);
  966.       return 1;
  967.     }
  968.     }
  969.   return 0;
  970. }
  971.  
  972. /* Generate RTL to return from the current function, with no value.
  973.    (That is, we do not do anything about returning any value.)  */
  974.  
  975. void
  976. expand_null_return ()
  977. {
  978.   clear_pending_stack_adjust ();
  979. #ifdef FUNCTION_EPILOGUE
  980.   expand_goto_internal (0, return_label);
  981. #else
  982.   emit_jump_insn (gen_return ());
  983.   emit_barrier ();
  984. #endif
  985.   last_expr_type = 0;
  986. }
  987.  
  988. /* Generate RTL to evaluate the expression RETVAL and return it
  989.    from the current function.  */
  990.  
  991. void
  992. expand_return (retval)
  993.      tree retval;
  994. {
  995.   register rtx val = 0;
  996.   register rtx op0;
  997.   int really_for_value =
  998.     (TREE_CODE (retval) == MODIFY_EXPR
  999.      && TREE_CODE (TREE_OPERAND (retval, 0)) == RESULT_DECL);
  1000.  
  1001.   /* For tail-recursive call to current function,
  1002.      just jump back to the beginning.
  1003.      It's unsafe if any auto variable in this function
  1004.      has its address taken; for simplicity,
  1005.      require stack frame to be empty.  */
  1006.   if (optimize && really_for_value
  1007.       && frame_offset == STARTING_FRAME_OFFSET
  1008.       && TREE_CODE (TREE_OPERAND (retval, 1)) == CALL_EXPR
  1009.       && TREE_CODE (TREE_OPERAND (TREE_OPERAND (retval, 1), 0)) == ADDR_EXPR
  1010.       && TREE_OPERAND (TREE_OPERAND (TREE_OPERAND (retval, 1), 0), 0) == this_function
  1011.       /* Finish checking validity, and if valid emit code
  1012.      to set the argument variables for the new call.  */
  1013.       && tail_recursion_args (TREE_OPERAND (TREE_OPERAND (retval, 1), 1),
  1014.                   DECL_ARGUMENTS (this_function)))
  1015.     {
  1016.       ;
  1017.       if (tail_recursion_label == 0)
  1018.     {
  1019.       tail_recursion_label = gen_label_rtx ();
  1020.       emit_label_after (tail_recursion_label,
  1021.                 tail_recursion_reentry);
  1022.     }
  1023.       expand_goto_internal (0, tail_recursion_label);
  1024.       emit_barrier ();
  1025.       return;
  1026.     }
  1027. #ifndef FUNCTION_EPILOGUE
  1028.   /* If this is  return x == y;  then generate
  1029.      if (x == y) return 1; else return 0;
  1030.      if we can do it with explicit return insns.  */
  1031.   if (really_for_value)
  1032.     switch (TREE_CODE (TREE_OPERAND (retval, 1)))
  1033.       {
  1034.       case EQ_EXPR:
  1035.       case NE_EXPR:
  1036.       case GT_EXPR:
  1037.       case GE_EXPR:
  1038.       case LT_EXPR:
  1039.       case LE_EXPR:
  1040.       case TRUTH_ANDIF_EXPR:
  1041.       case TRUTH_ORIF_EXPR:
  1042.       case TRUTH_NOT_EXPR:
  1043.     op0 = gen_label_rtx ();
  1044.     val = DECL_RTL (DECL_RESULT (this_function));
  1045.     jumpifnot (TREE_OPERAND (retval, 1), op0);
  1046.     emit_move_insn (val, const1_rtx);
  1047.     emit_insn (gen_rtx (USE, VOIDmode, val));
  1048.     expand_null_return ();
  1049.     emit_label (op0);
  1050.     emit_move_insn (val, const0_rtx);
  1051.     emit_insn (gen_rtx (USE, VOIDmode, val));
  1052.     expand_null_return ();
  1053.     return;
  1054.       }
  1055. #endif
  1056.   val = expand_expr (retval, 0, VOIDmode, 0);
  1057.   emit_queue ();
  1058.  
  1059.   if (really_for_value && GET_CODE (val) == REG)
  1060.     emit_insn (gen_rtx (USE, VOIDmode, val));
  1061.  
  1062.   expand_null_return ();
  1063. }
  1064.  
  1065. /* Return 1 if the end of the generated RTX is not a barrier.
  1066.    This means code already compiled can drop through.  */
  1067.  
  1068. int
  1069. drop_through_at_end_p ()
  1070. {
  1071.   rtx insn = get_last_insn ();
  1072.   while (insn && GET_CODE (insn) == NOTE)
  1073.     insn = PREV_INSN (insn);
  1074.   return insn && GET_CODE (insn) != BARRIER;
  1075. }
  1076.  
  1077. /* Emit code to alter this function's formal parms for a tail-recursive call.
  1078.    ACTUALS is a list of actual parameter expressions (chain of TREE_LISTs).
  1079.    FORMALS is the chain of decls of formals.
  1080.    Return 1 if this can be done;
  1081.    otherwise return 0 and do not emit any code.  */
  1082.  
  1083. static int
  1084. tail_recursion_args (actuals, formals)
  1085.      tree actuals, formals;
  1086. {
  1087.   register tree a = actuals, f = formals;
  1088.   register int i;
  1089.   register rtx *argvec;
  1090.  
  1091.   /* Check that number and types of actuals are compatible
  1092.      with the formals.  This is not always true in valid C code.
  1093.      Also check that no formal needs to be addressable
  1094.      and that all formals are scalars.  */
  1095.  
  1096.   /* Also count the args.  */
  1097.  
  1098.   for (a = actuals, f = formals, i = 0; a && f; a = TREE_CHAIN (a), f = TREE_CHAIN (f), i++)
  1099.     {
  1100.       if (TREE_TYPE (TREE_VALUE (a)) != TREE_TYPE (f))
  1101.     return 0;
  1102.       if (GET_CODE (DECL_RTL (f)) != REG || DECL_MODE (f) == BLKmode)
  1103.     return 0;
  1104.     }
  1105.   if (a != 0 || f != 0)
  1106.     return 0;
  1107.  
  1108.   /* Compute all the actuals.  */
  1109.  
  1110.   argvec = (rtx *) alloca (i * sizeof (rtx));
  1111.  
  1112.   for (a = actuals, i = 0; a; a = TREE_CHAIN (a), i++)
  1113.     argvec[i] = expand_expr (TREE_VALUE (a), 0, VOIDmode, 0);
  1114.  
  1115.   /* Find which actual values refer to current values of previous formals.
  1116.      Copy each of them now, before any formal is changed.  */
  1117.  
  1118.   for (a = actuals, i = 0; a; a = TREE_CHAIN (a), i++)
  1119.     {
  1120.       int copy = 0;
  1121.       register int j;
  1122.       for (f = formals, j = 0; j < i; f = TREE_CHAIN (f), j++)
  1123.     if (reg_mentioned_p (DECL_RTL (f), argvec[i]))
  1124.       { copy = 1; break; }
  1125.       if (copy)
  1126.     argvec[i] = copy_to_reg (argvec[i]);
  1127.     }
  1128.  
  1129.   /* Store the values of the actuals into the formals.  */
  1130.  
  1131.   for (f = formals, a = actuals, i = 0; f;
  1132.        f = TREE_CHAIN (f), a = TREE_CHAIN (a), i++)
  1133.     {
  1134.       if (DECL_MODE (f) == GET_MODE (argvec[i]))
  1135.     emit_move_insn (DECL_RTL (f), argvec[i]);
  1136.       else
  1137.     convert_move (DECL_RTL (f), argvec[i],
  1138.               TREE_UNSIGNED (TREE_TYPE (TREE_VALUE (a))));
  1139.     }
  1140.  
  1141.   return 1;
  1142. }
  1143.  
  1144. /* Generate the RTL code for entering a binding contour.
  1145.    The variables are declared one by one, by calls to `expand_decl'.
  1146.  
  1147.    EXIT_FLAG is nonzero if this construct should be visible to
  1148.    `exit_something'.  */
  1149.  
  1150. void
  1151. expand_start_bindings (exit_flag)
  1152.      int exit_flag;
  1153. {
  1154.   struct nesting *thisblock
  1155.     = (struct nesting *) xmalloc (sizeof (struct nesting));
  1156.  
  1157.   rtx note = emit_note (0, NOTE_INSN_BLOCK_BEG);
  1158.  
  1159.   /* Make an entry on block_stack for the block we are entering.  */
  1160.  
  1161.   thisblock->next = block_stack;
  1162.   thisblock->all = nesting_stack;
  1163.   thisblock->depth = ++nesting_depth;
  1164.   thisblock->data.block.stack_level = 0;
  1165.   thisblock->data.block.label_chain = 0;
  1166.   thisblock->data.block.innermost_stack_block = stack_block_stack;
  1167.   thisblock->data.block.first_insn = note;
  1168.   thisblock->exit_label = exit_flag ? gen_label_rtx () : 0;
  1169.   block_stack = thisblock;
  1170.   nesting_stack = thisblock;
  1171. }
  1172.  
  1173. /* Output a USE for any register use in RTL.
  1174.    This is used with -noreg to mark the extent of lifespan
  1175.    of any registers used in a user-visible variable's DECL_RTL.  */
  1176.  
  1177. static void
  1178. use_variable (rtl)
  1179.      rtx rtl;
  1180. {
  1181.   if (GET_CODE (rtl) == REG)
  1182.     /* This is a register variable.  */
  1183.     emit_insn (gen_rtx (USE, VOIDmode, rtl));
  1184.   else if (GET_CODE (rtl) == MEM
  1185.        && GET_CODE (XEXP (rtl, 0)) == REG
  1186.        && XEXP (rtl, 0) != frame_pointer_rtx
  1187.        && XEXP (rtl, 0) != arg_pointer_rtx)
  1188.     /* This is a variable-sized structure.  */
  1189.     emit_insn (gen_rtx (USE, VOIDmode, XEXP (rtl, 0)));
  1190. }
  1191.  
  1192. /* Generate RTL code to terminate a binding contour.
  1193.    VARS is the chain of VAR_DECL nodes
  1194.    for the variables bound in this contour.
  1195.    MARK_ENDs is nonzero if we should put a note at the beginning
  1196.    and end of this binding contour.  */
  1197.  
  1198. void
  1199. expand_end_bindings (vars, mark_ends)
  1200.      tree vars;
  1201.      int mark_ends;
  1202. {
  1203.   register struct nesting *thisblock = block_stack;
  1204.   register tree decl;
  1205.  
  1206.   /* Mark the beginning and end of the scope if requested.  */
  1207.  
  1208.   if (mark_ends)
  1209.     emit_note (0, NOTE_INSN_BLOCK_END);
  1210.   else
  1211.     /* Get rid of the beginning-mark if we don't make an end-mark.  */
  1212.     NOTE_LINE_NUMBER (thisblock->data.block.first_insn) = NOTE_INSN_DELETED;
  1213.  
  1214.   if (thisblock->exit_label)
  1215.     {
  1216.       do_pending_stack_adjust ();
  1217.       emit_label (thisblock->exit_label);
  1218.     }
  1219.  
  1220.   /* Restore stack level in effect before the block
  1221.      (only if variable-size objects allocated).  */
  1222.  
  1223.   if (thisblock->data.block.stack_level != 0)
  1224.     {
  1225.       struct label_chain *chain;
  1226.  
  1227.       do_pending_stack_adjust ();
  1228.       emit_move_insn (stack_pointer_rtx,
  1229.               thisblock->data.block.stack_level);
  1230.  
  1231.       /* Any labels in this block are no longer valid to go to.
  1232.      Mark them to cause an error message.  */
  1233.       for (chain = thisblock->data.block.label_chain; chain; chain = chain->next)
  1234.     {
  1235.       TREE_PACKED (chain->label) = 1;
  1236.       /* If any goto without a fixup came to this label,
  1237.          that must be an error, because gotos without fixups
  1238.          come from outside all saved stack-levels.  */
  1239.       if (TREE_ADDRESSABLE (chain->label))
  1240.         error_with_file_and_line (DECL_SOURCE_FILE (chain->label),
  1241.                       DECL_SOURCE_LINE (chain->label),
  1242.                       "label \"%s\" was used \
  1243. before containing binding contour",
  1244.                       IDENTIFIER_POINTER (DECL_NAME (chain->label)));
  1245.     }
  1246.  
  1247.       /* Any gotos out of this block must also restore the stack level.
  1248.      Also report any gotos with fixups that came to labels in this level.  */
  1249.       fixup_gotos (thisblock->data.block.stack_level,
  1250.            thisblock->data.block.first_insn);
  1251.     }
  1252.  
  1253.   /* If doing stupid register allocation, make sure lives of all
  1254.      register variables declared here extend thru end of scope.  */
  1255.  
  1256.   if (obey_regdecls)
  1257.     for (decl = vars; decl; decl = TREE_CHAIN (decl))
  1258.       {
  1259.     rtx rtl = DECL_RTL (decl);
  1260.     if (TREE_CODE (decl) == VAR_DECL && rtl != 0)
  1261.       use_variable (rtl);
  1262.       }
  1263.  
  1264.   /* Restore block_stack level for containing block.  */
  1265.  
  1266.   stack_block_stack = thisblock->data.block.innermost_stack_block;
  1267.   POPSTACK (block_stack);
  1268. }
  1269.  
  1270. /* Generate RTL for the automatic variable declaration DECL.
  1271.    (Other kinds of declarations are simply ignored.)  */
  1272.  
  1273. void
  1274. expand_decl (decl)
  1275.      register tree decl;
  1276. {
  1277.   struct nesting *thisblock = block_stack;
  1278.   tree type = TREE_TYPE (decl);
  1279.  
  1280.   /* External function declarations are supposed to have been
  1281.      handled in assemble_variable.  Verify this.  */
  1282.   if (TREE_CODE (decl) == FUNCTION_DECL)
  1283.     {
  1284.       if (DECL_RTL (decl) == 0)
  1285.     abort ();
  1286.       return;
  1287.     }
  1288.  
  1289.   /* Aside from that, only automatic variables need any expansion done.
  1290.      Static and external variables were handled by `assemble_variable'
  1291.      (called from finish_decl).  TYPE_DECL and CONST_DECL require nothing;
  1292.      PARM_DECLs are handled in `assign_parms'.  */
  1293.  
  1294.   if (TREE_CODE (decl) != VAR_DECL)
  1295.     return;
  1296.   if (TREE_STATIC (decl) || TREE_EXTERNAL (decl))
  1297.     return;
  1298.  
  1299.   /* Create the RTL representation for the variable.  */
  1300.  
  1301.   if (type == error_mark_node)
  1302.     DECL_RTL (decl) = gen_rtx (MEM, BLKmode, const0_rtx);
  1303.   else if (DECL_MODE (decl) != BLKmode
  1304.        /* If -ffloat-store, don't put explicit float vars
  1305.           into regs.  */
  1306.        && !(flag_float_store
  1307.         && TREE_CODE (type) == REAL_TYPE)
  1308.        && ! TREE_VOLATILE (decl)
  1309.        && ! TREE_ADDRESSABLE (decl)
  1310.        && (TREE_REGDECL (decl) || ! obey_regdecls))
  1311.     {
  1312.       /* Automatic variable that can go in a register.  */
  1313.       DECL_RTL (decl) = gen_reg_rtx (DECL_MODE (decl));
  1314.       if (TREE_CODE (type) == POINTER_TYPE)
  1315.     mark_reg_pointer (DECL_RTL (decl));
  1316.       DECL_RTL (decl)->volatil = 1;
  1317.     }
  1318.   else if (DECL_SIZE (decl) == 0)
  1319.     /* Variable with incomplete type.  */
  1320.     /* Error message was already done; now avoid a crash.  */
  1321.     DECL_RTL (decl) = assign_stack_local (DECL_MODE (decl), 0);
  1322.   else if (TREE_LITERAL (DECL_SIZE (decl)))
  1323.     {
  1324.       /* Variable of fixed size that goes on the stack.  */
  1325.       DECL_RTL (decl)
  1326.     = assign_stack_local (DECL_MODE (decl),
  1327.                   (TREE_INT_CST_LOW (DECL_SIZE (decl))
  1328.                    * DECL_SIZE_UNIT (decl)
  1329.                    + BITS_PER_UNIT - 1)
  1330.                   / BITS_PER_UNIT);
  1331.       /* If this is a memory ref that contains aggregate components,
  1332.      mark it as such for cse and loop optimize.  */
  1333.       DECL_RTL (decl)->in_struct
  1334.     = (TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE
  1335.        || TREE_CODE (TREE_TYPE (decl)) == RECORD_TYPE
  1336.        || TREE_CODE (TREE_TYPE (decl)) == UNION_TYPE);
  1337.     }
  1338.   else
  1339.     /* Dynamic-size object: must push space on the stack.  */
  1340.     {
  1341.       rtx address, size;
  1342.  
  1343.       frame_pointer_needed = 1;
  1344.  
  1345.       /* Record the stack pointer on entry to block, if have
  1346.      not already done so.  */
  1347.       if (thisblock->data.block.stack_level == 0)
  1348.     {
  1349.       do_pending_stack_adjust ();
  1350.       thisblock->data.block.stack_level
  1351.         = copy_to_reg (stack_pointer_rtx);
  1352.       stack_block_stack = thisblock;
  1353.     }
  1354.  
  1355.       /* Compute the variable's size, in bytes.  */
  1356.       size = expand_expr (convert_units (DECL_SIZE (decl),
  1357.                      DECL_SIZE_UNIT (decl),
  1358.                      BITS_PER_UNIT),
  1359.               0, VOIDmode, 0);
  1360.  
  1361.       /* Round it up to this machine's required stack boundary.  */
  1362. #ifdef STACK_BOUNDARY
  1363.       /* Avoid extra code if we can prove it's a multiple already.  */
  1364.       if (DECL_SIZE_UNIT (decl) % STACK_BOUNDARY)
  1365.     size = round_push (size);
  1366. #endif
  1367.  
  1368.       /* Make space on the stack, and get an rtx for the address of it.  */
  1369. #ifdef STACK_GROWS_DOWNWARD
  1370.       anti_adjust_stack (size);
  1371. #endif
  1372.       address = copy_to_reg (stack_pointer_rtx);
  1373. #ifdef STACK_POINTER_OFFSET
  1374.       /* If the contents of the stack pointer reg are offset from the
  1375.      actual top-of-stack address, add the offset here.  */
  1376.       emit_insn (gen_add2_insn (address, gen_rtx (CONST_INT, VOIDmode,
  1377.                           STACK_POINTER_OFFSET)));
  1378. #endif
  1379. #ifndef STACK_GROWS_DOWNWARD
  1380.       anti_adjust_stack (size);
  1381. #endif
  1382.  
  1383.       /* Reference the variable indirect through that rtx.  */
  1384.       DECL_RTL (decl) = gen_rtx (MEM, DECL_MODE (decl), address);
  1385.     }
  1386.  
  1387.   if (TREE_VOLATILE (decl))
  1388.     DECL_RTL (decl)->volatil = 1;
  1389.   if (TREE_READONLY (decl))
  1390.     DECL_RTL (decl)->unchanging = 1;
  1391.  
  1392.   /* If doing stupid register allocation, make sure life of any
  1393.      register variable starts here, at the start of its scope.  */
  1394.  
  1395.   if (obey_regdecls
  1396.       && TREE_CODE (decl) == VAR_DECL
  1397.       && DECL_RTL (decl) != 0)
  1398.     use_variable (DECL_RTL (decl));
  1399.  
  1400.   /* Compute and store the initial value now.  */
  1401.  
  1402.   if (DECL_INITIAL (decl) == error_mark_node)
  1403.     {
  1404.       enum tree_code code = TREE_CODE (TREE_TYPE (decl));
  1405.       if (code == INTEGER_TYPE || code == REAL_TYPE || code == ENUMERAL_TYPE
  1406.       || code == POINTER_TYPE)
  1407.     expand_assignment (decl, convert (TREE_TYPE (decl), integer_zero_node),
  1408.                0, 0);
  1409.       emit_queue ();
  1410.     }
  1411.   else if (DECL_INITIAL (decl))
  1412.     {
  1413.       emit_note (DECL_SOURCE_FILE (decl), DECL_SOURCE_LINE (decl));
  1414.       expand_assignment (decl, DECL_INITIAL (decl), 0, 0);
  1415.       emit_queue ();
  1416.     }
  1417. }
  1418.  
  1419. /* Enter a case (Pascal) or switch (C) statement.
  1420.    Push a block onto case_stack and nesting_stack
  1421.    to accumulate the case-labels that are seen
  1422.    and to record the labels generated for the statement.
  1423.  
  1424.    EXIT_FLAG is nonzero if `exit_something' should exit this case stmt.
  1425.    Otherwise, this construct is transparent for `exit_something'.
  1426.  
  1427.    EXPR is the index-expression to be dispatched on.
  1428.    TYPE is its nominal type.  We could simply convert EXPR to this type,
  1429.    but instead we take short cuts.  */
  1430.  
  1431. void
  1432. expand_start_case (exit_flag, expr, type)
  1433.      int exit_flag;
  1434.      tree expr;
  1435.      tree type;
  1436. {
  1437.   register struct nesting *thiscase
  1438.     = (struct nesting *) xmalloc (sizeof (struct nesting));
  1439.  
  1440.   /* Make an entry on case_stack for the case we are entering.  */
  1441.  
  1442.   thiscase->next = case_stack;
  1443.   thiscase->all = nesting_stack;
  1444.   thiscase->depth = ++nesting_depth;
  1445.   thiscase->exit_label = exit_flag ? gen_label_rtx () : 0;
  1446.   thiscase->data.case_stmt.case_list = 0;
  1447.   thiscase->data.case_stmt.index_expr = expr;
  1448.   thiscase->data.case_stmt.nominal_type = type;
  1449.   case_stack = thiscase;
  1450.   nesting_stack = thiscase;
  1451.  
  1452.   do_pending_stack_adjust ();
  1453.  
  1454.   /* Make sure case_stmt.start points to something that won't
  1455.      need any transformation before expand_end_case.  */
  1456.   if (GET_CODE (get_last_insn ()) != NOTE)
  1457.     emit_note (0, NOTE_INSN_DELETED);
  1458.  
  1459.   thiscase->data.case_stmt.start = get_last_insn ();
  1460. }
  1461.  
  1462. /* Start a "dummy case statement" within which case labels are invalid
  1463.    and are not connected to any larger real case statement.
  1464.    This can be used if you don't want to let a case statement jump
  1465.    into the middle of certain kinds of constructs.  */
  1466.  
  1467. void
  1468. expand_start_case_dummy ()
  1469. {
  1470.   register struct nesting *thiscase
  1471.     = (struct nesting *) xmalloc (sizeof (struct nesting));
  1472.  
  1473.   /* Make an entry on case_stack for the dummy.  */
  1474.  
  1475.   thiscase->next = case_stack;
  1476.   thiscase->all = nesting_stack;
  1477.   thiscase->depth = ++nesting_depth;
  1478.   thiscase->exit_label = 0;
  1479.   thiscase->data.case_stmt.case_list = 0;
  1480.   thiscase->data.case_stmt.start = 0;
  1481.   thiscase->data.case_stmt.nominal_type = 0;
  1482.   case_stack = thiscase;
  1483.   nesting_stack = thiscase;
  1484. }
  1485.  
  1486. /* End a dummy case statement.  */
  1487.  
  1488. void
  1489. expand_end_case_dummy ()
  1490. {
  1491.   POPSTACK (case_stack);
  1492. }
  1493.  
  1494. /* Accumulate one case or default label inside a case or switch statement.
  1495.    VALUE is the value of the case (a null pointer, for a default label).
  1496.  
  1497.    If not currently inside a case or switch statement, return 1 and do
  1498.    nothing.  The caller will print a language-specific error message.
  1499.    If VALUE is a duplicate, return 2 and do nothing.
  1500.    If VALUE is out of range, return 3 and do nothing.
  1501.    Return 0 on success.  */
  1502.  
  1503. int
  1504. pushcase (value, label)
  1505.      register tree value;
  1506.      register tree label;
  1507. {
  1508.   register tree l;
  1509.   tree index_type;
  1510.   tree nominal_type;
  1511.  
  1512.   /* Fail if not inside a real case statement.  */
  1513.   if (! (case_stack && case_stack->data.case_stmt.start))
  1514.     return 1;
  1515.  
  1516.   index_type = TREE_TYPE (case_stack->data.case_stmt.index_expr);
  1517.   nominal_type = case_stack->data.case_stmt.nominal_type;
  1518.  
  1519.   /* If the index is erroneous, avoid more problems: pretend to succeed.  */
  1520.   if (index_type == error_mark_node)
  1521.     return 0;
  1522.  
  1523.   /* Convert VALUE to the type in which the comparisons are nominally done.  */
  1524.   if (value != 0)
  1525.     value = convert (nominal_type, value);
  1526.  
  1527.   /* Fail if this is a duplicate entry.  */
  1528.   for (l = case_stack->data.case_stmt.case_list; l; l = TREE_CHAIN (l))
  1529.     {
  1530.       if (value == 0 && TREE_PURPOSE (l) == 0)
  1531.     return 2;
  1532.       if (value != 0 && TREE_PURPOSE (l)
  1533.       && (TREE_INT_CST_LOW (value)
  1534.           == TREE_INT_CST_LOW (TREE_PURPOSE (l)))
  1535.       && (TREE_INT_CST_HIGH (value)
  1536.           == TREE_INT_CST_HIGH (TREE_PURPOSE (l))))
  1537.     return 2;
  1538.     }
  1539.  
  1540.   /* Fail if this value is out of range for the actual type of the index
  1541.      (which may be narrower than NOMINAL_TYPE).  */
  1542.   if (value != 0 && ! int_fits_type_p (value, index_type))
  1543.     return 3;
  1544.  
  1545.   /* Add this label to the list, and succeed.
  1546.      Copy VALUE so it is temporary rather than momentary.  */
  1547.   case_stack->data.case_stmt.case_list
  1548.     = tree_cons (value ? copy_node (value) : 0, label,
  1549.              case_stack->data.case_stmt.case_list);
  1550.   expand_label (label);
  1551.   return 0;
  1552. }
  1553.  
  1554. /* Terminate a case (Pascal) or switch (C) statement
  1555.    in which CASE_INDEX is the expression to be tested.
  1556.    Generate the code to test it and jump to the right place.  */
  1557.  
  1558. void
  1559. expand_end_case ()
  1560. {
  1561.   tree minval, maxval, range;
  1562.   rtx default_label = 0;
  1563.   register tree elt;
  1564.   register tree c;
  1565.   int count;
  1566.   rtx index;
  1567.   rtx table_label = gen_label_rtx ();
  1568.   int ncases;
  1569.   rtx *labelvec;
  1570.   register int i;
  1571.   rtx before_case;
  1572.   register struct nesting *thiscase = case_stack;
  1573.   tree index_expr = thiscase->data.case_stmt.index_expr;
  1574.  
  1575.   do_pending_stack_adjust ();
  1576.  
  1577.   /* An ERROR_MARK occurs for various reasons including invalid data type.  */
  1578.   if (TREE_TYPE (index_expr) != error_mark_node)
  1579.     {
  1580.       /* If we don't have a default-label, create one here,
  1581.      after the body of the switch.  */
  1582.       for (c = thiscase->data.case_stmt.case_list; c; c = TREE_CHAIN (c))
  1583.     if (TREE_PURPOSE (c) == 0)
  1584.       break;
  1585.       if (c == 0)
  1586.     pushcase (0, build_decl (LABEL_DECL, NULL_TREE, NULL_TREE));
  1587.  
  1588.       before_case = get_last_insn ();
  1589.  
  1590.       /* Get upper and lower bounds of case values.
  1591.      Also convert all the case values to the index expr's data type.  */
  1592.       count = 0;
  1593.       for (c = thiscase->data.case_stmt.case_list; c; c = TREE_CHAIN (c))
  1594.     if (elt = TREE_PURPOSE (c))
  1595.       {
  1596.         /* Note that in Pascal it will be possible
  1597.            to have a RANGE_EXPR here as long as both
  1598.            ends of the range are constant.
  1599.            It will be necessary to extend this function
  1600.            to handle them.  */
  1601.         if (TREE_CODE (elt) != INTEGER_CST)
  1602.           abort ();
  1603.  
  1604.         TREE_PURPOSE (c) = elt = convert (TREE_TYPE (index_expr), elt);
  1605.  
  1606.         /* Count the elements and track the largest and
  1607.            smallest of them
  1608.            (treating them as signed even if they are not).  */
  1609.         if (count++ == 0)
  1610.           {
  1611.         minval = maxval = elt;
  1612.           }
  1613.         else
  1614.           {
  1615.         if (INT_CST_LT (elt, minval))
  1616.           minval = elt;
  1617.         if (INT_CST_LT (maxval, elt))
  1618.           maxval = elt;
  1619.           }
  1620.       }
  1621.     else
  1622.       default_label = label_rtx (TREE_VALUE (c));
  1623.  
  1624.       if (default_label == 0)
  1625.     abort ();
  1626.  
  1627.       /* Compute span of values.  */
  1628.       if (count != 0)
  1629.     range = combine (MINUS_EXPR, maxval, minval);
  1630.  
  1631.       if (count == 0 || TREE_CODE (TREE_TYPE (index_expr)) == ERROR_MARK)
  1632.     {
  1633.       expand_expr (index_expr, const0_rtx, VOIDmode, 0);
  1634.       emit_queue ();
  1635.       emit_jump (default_label);
  1636.     }
  1637.       /* If range of values is much bigger than number of values,
  1638.      make a sequence of conditional branches instead of a dispatch.
  1639.      If the switch-index is a constant, do it this way
  1640.      because we can optimize it.  */
  1641.       else if (TREE_INT_CST_HIGH (range) != 0
  1642. #ifdef HAVE_casesi
  1643.            || count < 4
  1644. #else
  1645.            /* If machine does not have a case insn that compares the
  1646.           bounds, this means extra overhead for dispatch tables
  1647.           which raises the threshold for using them.  */
  1648.            || count < 5
  1649. #endif
  1650.            || (unsigned) (TREE_INT_CST_LOW (range)) > 10 * count
  1651.            || TREE_CODE (index_expr) == INTEGER_CST)
  1652.     {
  1653.       index = expand_expr (index_expr, 0, VOIDmode, 0);
  1654.       emit_queue ();
  1655.  
  1656.       index = protect_from_queue (index, 0);
  1657.       if (GET_CODE (index) == MEM)
  1658.         index = copy_to_reg (index);
  1659.       do_pending_stack_adjust ();
  1660.  
  1661.       for (c = thiscase->data.case_stmt.case_list; c; c = TREE_CHAIN (c))
  1662.         {
  1663.           elt = TREE_PURPOSE (c);
  1664.           if (elt && TREE_VALUE (c))
  1665.         do_jump_if_equal (index, expand_expr (elt, 0, VOIDmode, 0),
  1666.                   label_rtx (TREE_VALUE (c)));
  1667.         }
  1668.  
  1669.       emit_jump (default_label);
  1670.     }
  1671.       else
  1672.     {
  1673. #ifdef HAVE_casesi
  1674.       /* Convert the index to SImode.  */
  1675.       if (TYPE_MODE (TREE_TYPE (index_expr)) == DImode)
  1676.         {
  1677.           index_expr = build (MINUS_EXPR, TREE_TYPE (index_expr),
  1678.                   index_expr, minval);
  1679.           minval = integer_zero_node;
  1680.         }
  1681.       if (TYPE_MODE (TREE_TYPE (index_expr)) != SImode)
  1682.         index_expr = convert (type_for_size (GET_MODE_BITSIZE (SImode), 0),
  1683.                   index_expr);
  1684.       index = expand_expr (index_expr, 0, VOIDmode, 0);
  1685.       emit_queue ();
  1686.       index = protect_from_queue (index, 0);
  1687.       do_pending_stack_adjust ();
  1688.  
  1689.       emit_jump_insn (gen_casesi (index, expand_expr (minval, 0, VOIDmode, 0),
  1690.                       expand_expr (range, 0, VOIDmode, 0),
  1691.                       table_label, default_label));
  1692. #else
  1693. #ifdef HAVE_tablejump
  1694.       index_expr = convert (type_for_size (GET_MODE_BITSIZE (SImode), 0),
  1695.                 build (MINUS_EXPR, TREE_TYPE (index_expr),
  1696.                        index_expr, minval));
  1697.       index = expand_expr (index_expr, 0, VOIDmode, 0);
  1698.       emit_queue ();
  1699.       index = protect_from_queue (index, 0);
  1700.       do_pending_stack_adjust ();
  1701.  
  1702.       do_tablejump (index,
  1703.             gen_rtx (CONST_INT, VOIDmode, TREE_INT_CST_LOW (range)),
  1704.             table_label, default_label);
  1705. #else
  1706.       lossage;
  1707. #endif                /* not HAVE_tablejump */
  1708. #endif                /* not HAVE_casesi */
  1709.  
  1710.       /* Get table of labels to jump to, in order of case index.  */
  1711.  
  1712.       ncases = TREE_INT_CST_LOW (range) + 1;
  1713.       labelvec = (rtx *) alloca (ncases * sizeof (rtx));
  1714.       bzero (labelvec, ncases * sizeof (rtx));
  1715.  
  1716.       for (c = thiscase->data.case_stmt.case_list; c; c = TREE_CHAIN (c))
  1717.         if (TREE_VALUE (c) && (elt = TREE_PURPOSE (c)))
  1718.           {
  1719.         register int i
  1720.           = TREE_INT_CST_LOW (elt) - TREE_INT_CST_LOW (minval);
  1721.         labelvec[i]
  1722.           = gen_rtx (LABEL_REF, Pmode, label_rtx (TREE_VALUE (c)));
  1723.           }
  1724.  
  1725.       /* Fill in the gaps with the default.  */
  1726.       for (i = 0; i < ncases; i++)
  1727.         if (labelvec[i] == 0)
  1728.           labelvec[i] = gen_rtx (LABEL_REF, Pmode, default_label);
  1729.  
  1730.       /* Output the table */
  1731.       emit_label (table_label);
  1732.  
  1733. #ifdef CASE_VECTOR_PC_RELATIVE
  1734.       emit_jump_insn (gen_rtx (ADDR_DIFF_VEC, CASE_VECTOR_MODE,
  1735.                    gen_rtx (LABEL_REF, Pmode, table_label),
  1736.                    gen_rtvec_v (ncases, labelvec)));
  1737. #else
  1738.       emit_jump_insn (gen_rtx (ADDR_VEC, CASE_VECTOR_MODE,
  1739.                    gen_rtvec_v (ncases, labelvec)));
  1740. #endif
  1741.       /* If the case insn drops through the table,
  1742.          after the table we must jump to the default-label.
  1743.          Otherwise record no drop-through after the table.  */
  1744. #ifdef CASE_DROPS_THROUGH
  1745.       emit_jump (default_label);
  1746. #else
  1747.       emit_barrier ();
  1748. #endif
  1749.     }
  1750.  
  1751.       reorder_insns (NEXT_INSN (before_case), get_last_insn (),
  1752.              thiscase->data.case_stmt.start);
  1753.     }
  1754.   if (thiscase->exit_label)
  1755.     emit_label (thiscase->exit_label);
  1756.  
  1757.   POPSTACK (case_stack);
  1758. }
  1759.  
  1760. /* Generate code to jump to LABEL if OP1 and OP2 are equal.  */
  1761. /* ??? This may need an UNSIGNEDP argument to work properly ??? */
  1762.  
  1763. void
  1764. do_jump_if_equal (op1, op2, label)
  1765.      rtx op1, op2, label;
  1766. {
  1767.   if (GET_CODE (op1) == CONST_INT
  1768.       && GET_CODE (op2) == CONST_INT)
  1769.     {
  1770.       if (INTVAL (op1) == INTVAL (op2))
  1771.     emit_jump (label);
  1772.     }
  1773.   else
  1774.     {
  1775.       emit_cmp_insn (op1, op2, 0, 0);
  1776.       emit_jump_insn (gen_beq (label));
  1777.     }
  1778. }
  1779.  
  1780. /* Allocate fixed slots in the stack frame of the current function.  */
  1781.  
  1782. /* Return size needed for stack frame based on slots so far allocated.  */
  1783.  
  1784. int
  1785. get_frame_size ()
  1786. {
  1787. #ifdef FRAME_GROWS_DOWNWARD
  1788.   return -frame_offset;
  1789. #else
  1790.   return frame_offset;
  1791. #endif
  1792. }
  1793.  
  1794. /* Allocate a stack slot of SIZE bytes and return a MEM rtx for it
  1795.    with machine mode MODE.  */
  1796.  
  1797. rtx
  1798. assign_stack_local (mode, size)
  1799.      enum machine_mode mode;
  1800.      int size;
  1801. {
  1802.   register rtx x, addr;
  1803.   int bigend_correction = 0;
  1804.  
  1805.   frame_pointer_needed = 1;
  1806.  
  1807.   /* Make each stack slot a multiple of the main allocation unit.  */
  1808.   size = (((size + (BIGGEST_ALIGNMENT / BITS_PER_UNIT) - 1)
  1809.        / (BIGGEST_ALIGNMENT / BITS_PER_UNIT))
  1810.       * (BIGGEST_ALIGNMENT / BITS_PER_UNIT));
  1811.  
  1812.   /* On a big-endian machine, if we are allocating more space than we will use,
  1813.      use the least significant bytes of those that are allocated.  */
  1814. #ifdef BYTES_BIG_ENDIAN
  1815.   if (mode != BLKmode)
  1816.     bigend_correction = size - GET_MODE_SIZE (mode);
  1817. #endif
  1818.  
  1819. #ifdef FRAME_GROWS_DOWNWARD
  1820.   frame_offset -= size;
  1821. #endif
  1822.   addr = gen_rtx (PLUS, Pmode, frame_pointer_rtx,
  1823.           gen_rtx (CONST_INT, VOIDmode,
  1824.                (frame_offset + bigend_correction)));
  1825. #ifndef FRAME_GROWS_DOWNWARD
  1826.   frame_offset += size;
  1827. #endif
  1828.  
  1829.   if (! memory_address_p (mode, addr))
  1830.     invalid_stack_slot = 1;
  1831.  
  1832.   x = gen_rtx (MEM, mode, addr);
  1833.  
  1834.   return x;
  1835. }
  1836.  
  1837. /* Retroactively move an auto variable from a register to a stack slot.
  1838.    This is done when an address-reference to the variable is seen.  */
  1839.  
  1840. void
  1841. put_var_into_stack (decl)
  1842.      tree decl;
  1843. {
  1844.   register rtx reg = DECL_RTL (decl);
  1845.   register rtx new;
  1846.  
  1847.   /* No need to do anything if decl has no rtx yet
  1848.      since in that case caller is setting TREE_ADDRESSABLE
  1849.      and a stack slot will be assigned when the rtl is made.  */
  1850.   if (reg == 0)
  1851.     return;
  1852.   if (GET_CODE (reg) != REG)
  1853.     return;
  1854.  
  1855.   new = parm_stack_loc (reg);
  1856.   if (new == 0)
  1857.     new = assign_stack_local (GET_MODE (reg), GET_MODE_SIZE (GET_MODE (reg)));
  1858.  
  1859.   /* If this is a memory ref that contains aggregate components,
  1860.      mark it as such for cse and loop optimize.  */
  1861.   reg->in_struct
  1862.     = (TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE
  1863.        || TREE_CODE (TREE_TYPE (decl)) == RECORD_TYPE
  1864.        || TREE_CODE (TREE_TYPE (decl)) == UNION_TYPE);
  1865.  
  1866.   XEXP (reg, 0) = XEXP (new, 0);
  1867.   PUT_CODE (reg, MEM);
  1868.   /* `volatil' bit means one thing for MEMs, another entirely for REGs.  */
  1869.   reg->volatil = 0;
  1870.  
  1871.   fixup_var_refs (reg);
  1872. }
  1873.  
  1874. static void
  1875. fixup_var_refs (var)
  1876.      rtx var;
  1877. {
  1878.   register rtx insn;
  1879.  
  1880.   /* Yes.  Must scan all insns for stack-refs that exceed the limit.  */
  1881.   for (insn = get_insns (); insn; )
  1882.     {
  1883.       rtx next = NEXT_INSN (insn);
  1884.       if (GET_CODE (insn) == INSN || GET_CODE (insn) == CALL_INSN
  1885.       || GET_CODE (insn) == JUMP_INSN)
  1886.     {
  1887.       /* The insn to load VAR from a home in the arglist
  1888.          is now a no-op.  When we see it, just delete it.  */
  1889.       if (GET_CODE (PATTERN (insn)) == SET
  1890.           && SET_DEST (PATTERN (insn)) == var
  1891.           && rtx_equal_p (SET_SRC (PATTERN (insn)), var))
  1892.         next = delete_insn (insn);
  1893.       else
  1894.         fixup_var_refs_1 (var, PATTERN (insn), insn);
  1895.     }
  1896.       insn = next;
  1897.     }
  1898. }
  1899.  
  1900. static rtx
  1901. fixup_var_refs_1 (var, x, insn)
  1902.      register rtx var;
  1903.      register rtx x;
  1904.      rtx insn;
  1905. {
  1906.   register int i;
  1907.   RTX_CODE code = GET_CODE (x);
  1908.   register char *fmt;
  1909.   register rtx tem;
  1910.  
  1911.   switch (code)
  1912.     {
  1913.     case MEM:
  1914.       if (var == x)
  1915.     {
  1916.       x = fixup_stack_1 (x, insn);
  1917.       tem = gen_reg_rtx (GET_MODE (x));
  1918.       emit_insn_before (gen_move_insn (tem, x), insn);
  1919.       return tem;
  1920.     }
  1921.       break;
  1922.  
  1923.     case REG:
  1924.     case CC0:
  1925.     case PC:
  1926.     case CONST_INT:
  1927.     case CONST:
  1928.     case SYMBOL_REF:
  1929.     case LABEL_REF:
  1930.     case CONST_DOUBLE:
  1931.       return x;
  1932.  
  1933.     case SIGN_EXTRACT:
  1934.     case ZERO_EXTRACT:
  1935.       /* Note that in some cases those types of expressions are altered
  1936.      by optimize_bit_field, and do not survive to get here.  */
  1937.     case SUBREG:
  1938.       tem = x;
  1939.       while (GET_CODE (tem) == SUBREG || GET_CODE (tem) == SIGN_EXTRACT
  1940.          || GET_CODE (tem) == ZERO_EXTRACT)
  1941.     tem = XEXP (tem, 0);
  1942.       if (tem == var)
  1943.     {
  1944.       x = fixup_stack_1 (x, insn);
  1945.       tem = gen_reg_rtx (GET_MODE (x));
  1946.       emit_insn_before (gen_move_insn (tem, x), insn);
  1947.       return tem;
  1948.     }
  1949.       break;
  1950.  
  1951.     case SET:
  1952.       /* First do special simplification of bit-field references.  */
  1953.       if (GET_CODE (SET_DEST (x)) == SIGN_EXTRACT
  1954.       || GET_CODE (SET_DEST (x)) == ZERO_EXTRACT)
  1955.     optimize_bit_field (x, insn, 0);
  1956.       if (GET_CODE (SET_SRC (x)) == SIGN_EXTRACT
  1957.       || GET_CODE (SET_SRC (x)) == ZERO_EXTRACT)
  1958.     optimize_bit_field (x, insn, 0);
  1959.  
  1960.       {
  1961.     rtx dest = SET_DEST (x);
  1962.     rtx src = SET_SRC (x);
  1963.     rtx outerdest = dest;
  1964.     rtx outersrc = src;
  1965.     int strictflag = GET_CODE (dest) == STRICT_LOW_PART;
  1966.  
  1967.     while (GET_CODE (dest) == SUBREG || GET_CODE (dest) == STRICT_LOW_PART
  1968.            || GET_CODE (dest) == SIGN_EXTRACT
  1969.            || GET_CODE (dest) == ZERO_EXTRACT)
  1970.       dest = XEXP (dest, 0);
  1971.     while (GET_CODE (src) == SUBREG
  1972.            || GET_CODE (src) == SIGN_EXTRACT
  1973.            || GET_CODE (src) == ZERO_EXTRACT)
  1974.       src = XEXP (src, 0);
  1975.  
  1976.     /* If VAR does not appear at the top level of the SET
  1977.        just scan the lower levels of the tree.  */
  1978.  
  1979.         if (src != var && dest != var)
  1980.       break;
  1981.  
  1982.     /* Clean up (SUBREG:SI (MEM:mode ...) 0)
  1983.        that may appear inside a SIGN_EXTRACT or ZERO_EXTRACT.
  1984.        This was legitimate when the MEM was a REG.  */
  1985.  
  1986.     if ((GET_CODE (outerdest) == SIGN_EXTRACT
  1987.          || GET_CODE (outerdest) == ZERO_EXTRACT)
  1988.         && GET_CODE (XEXP (outerdest, 0)) == SUBREG
  1989.         && SUBREG_REG (XEXP (outerdest, 0)) == var)
  1990.       XEXP (outerdest, 0) = fixup_memory_subreg (XEXP (outerdest, 0));
  1991.  
  1992.     if ((GET_CODE (outersrc) == SIGN_EXTRACT
  1993.          || GET_CODE (outersrc) == ZERO_EXTRACT)
  1994.         && GET_CODE (XEXP (outersrc, 0)) == SUBREG
  1995.         && SUBREG_REG (XEXP (outersrc, 0)) == var)
  1996.       XEXP (outersrc, 0) = fixup_memory_subreg (XEXP (outersrc, 0));
  1997.  
  1998.     /* Make sure a MEM inside a SIGN_EXTRACT has QImode
  1999.        since that's what bit-field insns want.  */
  2000.  
  2001.     if ((GET_CODE (outerdest) == SIGN_EXTRACT
  2002.          || GET_CODE (outerdest) == ZERO_EXTRACT)
  2003.         && GET_CODE (XEXP (outerdest, 0)) == MEM
  2004.         && GET_MODE (XEXP (outerdest, 0)) != QImode)
  2005.       {
  2006.         XEXP (outerdest, 0) = copy_rtx (XEXP (outerdest, 0));
  2007.         PUT_MODE (XEXP (outerdest, 0), QImode);
  2008.       }
  2009.  
  2010.     if ((GET_CODE (outersrc) == SIGN_EXTRACT
  2011.          || GET_CODE (outersrc) == ZERO_EXTRACT)
  2012.         && GET_CODE (XEXP (outersrc, 0)) == MEM
  2013.         && GET_MODE (XEXP (outersrc, 0)) != QImode)
  2014.       {
  2015.         XEXP (outersrc, 0) = copy_rtx (XEXP (outersrc, 0));
  2016.         PUT_MODE (XEXP (outersrc, 0), QImode);
  2017.       }
  2018.  
  2019.     /* STRICT_LOW_PART is a no-op on memory references
  2020.        and it can cause combinations to be unrecognizable,
  2021.        so eliminate it.  */
  2022.  
  2023.     if (dest == var && GET_CODE (SET_DEST (x)) == STRICT_LOW_PART)
  2024.       SET_DEST (x) = XEXP (SET_DEST (x), 0);
  2025.  
  2026.     /* An insn to copy VAR into or out of a register
  2027.        must be left alone, to avoid an infinite loop here.
  2028.        But do fix up the address of VAR's stack slot if nec.  */
  2029.  
  2030.     if (GET_CODE (SET_SRC (x)) == REG || GET_CODE (SET_DEST (x)) == REG)
  2031.       return fixup_stack_1 (x, insn);
  2032.  
  2033.     if ((GET_CODE (SET_SRC (x)) == SUBREG
  2034.          && GET_CODE (SUBREG_REG (SET_SRC (x))) == REG)
  2035.         || (GET_CODE (SET_DEST (x)) == SUBREG
  2036.         && GET_CODE (SUBREG_REG (SET_DEST (x))) == REG))
  2037.       return fixup_stack_1 (x, insn);
  2038.  
  2039.     /* Otherwise, storing into VAR must be handled specially
  2040.        by storing into a temporary and copying that into VAR
  2041.        with a new insn after this one.  */
  2042.  
  2043.     if (dest == var)
  2044.       {
  2045.         rtx temp;
  2046.         rtx fixeddest;
  2047.         tem = SET_DEST (x);
  2048.         if (GET_CODE (tem) == STRICT_LOW_PART)
  2049.           tem = XEXP (tem, 0);
  2050.         temp = gen_reg_rtx (GET_MODE (tem));
  2051.         fixeddest = fixup_stack_1 (SET_DEST (x), insn);
  2052.         emit_insn_after (gen_move_insn (fixeddest, temp), insn);
  2053.         SET_DEST (x) = temp;
  2054.       }
  2055.       }
  2056.     }
  2057.  
  2058.   /* Nothing special about this RTX; fix its operands.  */
  2059.  
  2060.   fmt = GET_RTX_FORMAT (code);
  2061.   for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
  2062.     {
  2063.       if (fmt[i] == 'e')
  2064.     XEXP (x, i) = fixup_var_refs_1 (var, XEXP (x, i), insn);
  2065.       if (fmt[i] == 'E')
  2066.     {
  2067.       register int j;
  2068.       for (j = 0; j < XVECLEN (x, i); j++)
  2069.         XVECEXP (x, i, j)
  2070.           = fixup_var_refs_1 (var, XVECEXP (x, i, j), insn);
  2071.     }
  2072.     }
  2073.   return x;
  2074. }
  2075.  
  2076. /* Given X, an rtx of the form (SUBREG:m1 (MEM:m2 addr)),
  2077.    return an rtx (MEM:m1 newaddr) which is equivalent.  */
  2078.  
  2079. static rtx
  2080. fixup_memory_subreg (x)
  2081.      rtx x;
  2082. {
  2083.   int offset = SUBREG_WORD (x) * UNITS_PER_WORD;
  2084.   rtx addr = XEXP (SUBREG_REG (x), 0);
  2085.   enum machine_mode mode = GET_MODE (SUBREG_REG (x));
  2086.  
  2087. #ifdef BYTES_BIG_ENDIAN
  2088.   offset += (MIN (UNITS_PER_WORD, GET_MODE_SIZE (mode))
  2089.          - MIN (UNITS_PER_WORD, GET_MODE_SIZE (GET_MODE (x))));
  2090. #endif
  2091.   return change_address (SUBREG_REG (x), mode,
  2092.              plus_constant (addr, offset));
  2093. }
  2094.  
  2095. #if 0
  2096. /* Fix up any references to stack slots that are invalid memory addresses
  2097.    because they exceed the maximum range of a displacement.  */
  2098.  
  2099. void
  2100. fixup_stack_slots ()
  2101. {
  2102.   register rtx insn;
  2103.  
  2104.   /* Did we generate a stack slot that is out of range
  2105.      or otherwise has an invalid address?  */
  2106.   if (invalid_stack_slot)
  2107.     {
  2108.       /* Yes.  Must scan all insns for stack-refs that exceed the limit.  */
  2109.       for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
  2110.     if (GET_CODE (insn) == INSN || GET_CODE (insn) == CALL_INSN
  2111.         || GET_CODE (insn) == JUMP_INSN)
  2112.       fixup_stack_1 (PATTERN (insn), insn);
  2113.     }
  2114. }
  2115. #endif
  2116.  
  2117. /* For each memory ref within X, if it refers to a stack slot
  2118.    with an out of range displacement, put the address in a temp register
  2119.    (emitting new insns before INSN to load these registers)
  2120.    and alter the memory ref to use that register.
  2121.    Replace each such MEM rtx with a copy, to avoid clobberage.  */
  2122.  
  2123. static rtx
  2124. fixup_stack_1 (x, insn)
  2125.      rtx x;
  2126.      rtx insn;
  2127. {
  2128.   register int i;
  2129.   register RTX_CODE code = GET_CODE (x);
  2130.   register char *fmt;
  2131.  
  2132.   if (code == MEM)
  2133.     {
  2134.       register rtx ad = XEXP (x, 0);
  2135.       /* If we have address of a stack slot but it's not valid
  2136.      (displacement is too large), compute the sum in a register.  */
  2137.       if (GET_CODE (ad) == PLUS
  2138.       && XEXP (ad, 0) == frame_pointer_rtx
  2139.       && GET_CODE (XEXP (ad, 1)) == CONST_INT)
  2140.     {
  2141.       rtx temp;
  2142.       if (memory_address_p (GET_MODE (x), ad))
  2143.         return x;
  2144.       temp = gen_reg_rtx (GET_MODE (ad));
  2145.       emit_insn_before (gen_move_insn (temp, ad), insn);
  2146.       return change_address (x, VOIDmode, temp);
  2147.     }
  2148.       return x;
  2149.     }
  2150.  
  2151.   fmt = GET_RTX_FORMAT (code);
  2152.   for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
  2153.     {
  2154.       if (fmt[i] == 'e')
  2155.     XEXP (x, i) = fixup_stack_1 (XEXP (x, i), insn);
  2156.       if (fmt[i] == 'E')
  2157.     {
  2158.       register int j;
  2159.       for (j = 0; j < XVECLEN (x, i); j++)
  2160.         XVECEXP (x, i, j) = fixup_stack_1 (XVECEXP (x, i, j), insn);
  2161.     }
  2162.     }
  2163.   return x;
  2164. }
  2165.  
  2166. /* Optimization: a bit-field instruction whose field
  2167.    happens to be a byte or halfword in memory
  2168.    can be changed to a move instruction.
  2169.  
  2170.    We call here when INSN is an insn to examine or store into a bit-field.
  2171.    BODY is the SET-rtx to be altered.
  2172.  
  2173.    EQUIV_MEM is the table `reg_equiv_mem' if that is available; else 0.
  2174.    (Currently this is called only from stmt.c, and EQUIV_MEM is always 0.)  */
  2175.  
  2176. static void
  2177. optimize_bit_field (body, insn, equiv_mem)
  2178.      rtx body;
  2179.      rtx insn;
  2180.      rtx *equiv_mem;
  2181. {
  2182.   register rtx bitfield;
  2183.   int destflag;
  2184.  
  2185.   if (GET_CODE (SET_DEST (body)) == SIGN_EXTRACT
  2186.       || GET_CODE (SET_DEST (body)) == ZERO_EXTRACT)
  2187.     bitfield = SET_DEST (body), destflag = 1;
  2188.   else
  2189.     bitfield = SET_SRC (body), destflag = 0;
  2190.  
  2191.   /* First check that the field being stored has constant size and position
  2192.      and is in fact a byte or halfword suitably aligned.  */
  2193.  
  2194.   if (GET_CODE (XEXP (bitfield, 1)) == CONST_INT
  2195.       && GET_CODE (XEXP (bitfield, 2)) == CONST_INT
  2196.       && (INTVAL (XEXP (bitfield, 1)) == GET_MODE_BITSIZE (QImode)
  2197.       || INTVAL (XEXP (bitfield, 1)) == GET_MODE_BITSIZE (HImode))
  2198.       && INTVAL (XEXP (bitfield, 2)) % INTVAL (XEXP (bitfield, 1)) == 0)
  2199.     {
  2200.       register rtx memref = 0;
  2201.  
  2202.       /* Now check that the contanting word is memory, not a register,
  2203.      and that it is safe to change the machine mode and to
  2204.      add something to the address.  */
  2205.  
  2206.       if (GET_CODE (XEXP (bitfield, 0)) == MEM)
  2207.     memref = XEXP (bitfield, 0);
  2208.       else if (GET_CODE (XEXP (bitfield, 0)) == REG
  2209.            && equiv_mem != 0
  2210.            && (memref = equiv_mem[REGNO (XEXP (bitfield, 0))]) != 0)
  2211.     ;
  2212.       else if (GET_CODE (XEXP (bitfield, 0)) == SUBREG
  2213.            && GET_CODE (SUBREG_REG (XEXP (bitfield, 0))) == MEM)
  2214.     memref = SUBREG_REG (XEXP (bitfield, 0));
  2215.       else if (GET_CODE (XEXP (bitfield, 0)) == SUBREG
  2216.            && equiv_mem != 0
  2217.            && GET_CODE (SUBREG_REG (XEXP (bitfield, 0))) == REG
  2218.            && (memref = equiv_mem[REGNO (SUBREG_REG (XEXP (bitfield, 0)))]) != 0)
  2219.     ;
  2220.  
  2221.       if (memref
  2222.       && ! mode_dependent_address_p (XEXP (memref, 0))
  2223.       && offsetable_address_p (GET_MODE (bitfield), XEXP (memref, 0)))
  2224.     {
  2225.       /* Now adjust the address, first for any subreg'ing
  2226.          that we are now getting rid of,
  2227.          and then for which byte of the word is wanted.  */
  2228.  
  2229.       register int offset
  2230.         = INTVAL (XEXP (bitfield, 2)) / GET_MODE_BITSIZE (QImode);
  2231.       if (GET_CODE (XEXP (bitfield, 0)) == SUBREG)
  2232.         {
  2233.           offset += SUBREG_WORD (XEXP (bitfield, 0)) * UNITS_PER_WORD;
  2234. #ifdef BYTES_BIG_ENDIAN
  2235.           offset -= (MIN (UNITS_PER_WORD,
  2236.                   GET_MODE_SIZE (GET_MODE (XEXP (bitfield, 0))))
  2237.              - MIN (UNITS_PER_WORD,
  2238.                 GET_MODE_SIZE (GET_MODE (memref))));
  2239. #endif
  2240.         }
  2241.       memref = gen_rtx (MEM,
  2242.                 (INTVAL (XEXP (bitfield, 1)) == GET_MODE_BITSIZE (QImode)
  2243.                  ? QImode : HImode),
  2244.                 XEXP (memref, 0));
  2245.  
  2246.       /* Store this memory reference where
  2247.          we found the bit field reference.  */
  2248.  
  2249.       if (destflag)
  2250.         {
  2251.           SET_DEST (body)
  2252.         = adj_offsetable_operand (memref, offset);
  2253.           if (! CONSTANT_ADDRESS_P (SET_SRC (body)))
  2254.         {
  2255.           rtx src = SET_SRC (body);
  2256.           while (GET_CODE (src) == SUBREG
  2257.              && SUBREG_WORD (src) == 0)
  2258.             src = SUBREG_REG (src);
  2259.           if (GET_MODE (src) != GET_MODE (memref))
  2260.             src = gen_rtx (SUBREG, GET_MODE (memref),
  2261.                    SET_SRC (body), 0);
  2262.           SET_SRC (body) = src;
  2263.         }
  2264.           else if (GET_MODE (SET_SRC (body)) != VOIDmode
  2265.                && GET_MODE (SET_SRC (body)) != GET_MODE (memref))
  2266.         /* This shouldn't happen because anything that didn't have
  2267.            one of these modes should have got converted explicitly
  2268.            and then referenced through a subreg.
  2269.            This is so because the original bit-field was
  2270.            handled by agg_mode and so its tree structure had
  2271.            the same mode that memref now has.  */
  2272.         abort ();
  2273.         }
  2274.       else
  2275.         {
  2276.           rtx newreg = gen_reg_rtx (GET_MODE (SET_DEST (body)));
  2277.           emit_insn_before (gen_extend_insn (newreg, adj_offsetable_operand (memref, offset),
  2278.                          GET_MODE (SET_DEST (body)),
  2279.                          GET_MODE (memref),
  2280.                          GET_CODE (SET_SRC (body)) == ZERO_EXTRACT),
  2281.                 insn);
  2282.           SET_SRC (body) = newreg;
  2283.         }
  2284.  
  2285.       /* Cause the insn to be re-recognized.  */
  2286.  
  2287.       INSN_CODE (insn) = -1;
  2288.     }
  2289.     }
  2290. }
  2291.  
  2292. /* 1 + last pseudo register number used for loading a copy
  2293.    of a parameter of this function.  */
  2294.  
  2295. static int max_parm_reg;
  2296.  
  2297. /* Vector indexed by REGNO, containing location on stack in which
  2298.    to put the parm which is nominally in pseudo register REGNO,
  2299.    if we discover that that parm must go in the stack.  */
  2300. static rtx *parm_reg_stack_loc;
  2301.  
  2302. /* Last insn of those whose job was to put parms into their nominal homes.  */
  2303. static rtx last_parm_insn;
  2304.  
  2305. int
  2306. max_parm_reg_num ()
  2307. {
  2308.   return max_parm_reg;
  2309. }
  2310.  
  2311. /* Return the first insn following those generated by `assign_parms'.  */
  2312.  
  2313. rtx
  2314. get_first_nonparm_insn ()
  2315. {
  2316.   if (last_parm_insn)
  2317.     return NEXT_INSN (last_parm_insn);
  2318.   return get_insns ();
  2319. }
  2320.  
  2321. /* Get the stack home of a REG rtx that is one of this function's parameters.
  2322.    This is called rather than assign a new stack slot as a local.
  2323.    Return 0 if there is no existing stack home suitable for such use.  */
  2324.  
  2325. static rtx
  2326. parm_stack_loc (reg)
  2327.      rtx reg;
  2328. {
  2329.   if (REGNO (reg) < max_parm_reg)
  2330.     return parm_reg_stack_loc[REGNO (reg)];
  2331.   return 0;
  2332. }
  2333.  
  2334. /* Assign RTL expressions to the function's parameters.
  2335.    This may involve copying them into registers and using
  2336.    those registers as the RTL for them.  */
  2337.  
  2338. static void
  2339. assign_parms (fndecl)
  2340.      tree fndecl;
  2341. {
  2342.   register tree parm;
  2343.   register rtx entry_parm;
  2344.   register rtx stack_parm;
  2345.   register CUMULATIVE_ARGS args_so_far;
  2346.   enum machine_mode passed_mode, nominal_mode;
  2347.   /* Total space needed so far for args on the stack,
  2348.      given as a constant and a tree-expression.  */
  2349.   struct args_size stack_args_size;
  2350.  
  2351.   int nparmregs
  2352.     = list_length (DECL_ARGUMENTS (fndecl)) + FIRST_PSEUDO_REGISTER;
  2353.  
  2354.   /* Nonzero if function takes extra anonymous args.
  2355.      This means the last named arg must be on the stack
  2356.      right before the anonymous ones.
  2357.      Also nonzero if the first arg is named `__builtin_va_alist',
  2358.      which is used on some machines for old-fashioned non-ANSI varargs.h;
  2359.      this too should be stuck onto the stack as if it had arrived there.  */
  2360.   int vararg
  2361.     = ((DECL_ARGUMENTS (fndecl) != 0
  2362.     && (! strcmp (IDENTIFIER_POINTER (DECL_NAME (DECL_ARGUMENTS (fndecl))),
  2363.               "__builtin_va_alist")))
  2364.        ||
  2365.        (TYPE_ARG_TYPES (TREE_TYPE (fndecl)) != 0
  2366.     && (TREE_VALUE (tree_last (TYPE_ARG_TYPES (TREE_TYPE (fndecl))))
  2367.         != void_type_node)));
  2368.  
  2369.   stack_args_size.constant = 0;
  2370.   stack_args_size.var = 0;
  2371.  
  2372.   /* If struct value address comes on the stack, count it in size of args.  */
  2373.   if (DECL_MODE (DECL_RESULT (fndecl)) == BLKmode
  2374.       && GET_CODE (struct_value_incoming_rtx) == MEM)
  2375.     stack_args_size.constant += GET_MODE_SIZE (Pmode);
  2376.  
  2377.   parm_reg_stack_loc = (rtx *) oballoc (nparmregs * sizeof (rtx));
  2378.   bzero (parm_reg_stack_loc, nparmregs * sizeof (rtx));
  2379.  
  2380.   INIT_CUMULATIVE_ARGS (args_so_far, TREE_TYPE (fndecl));
  2381.  
  2382.   for (parm = DECL_ARGUMENTS (fndecl); parm; parm = TREE_CHAIN (parm))
  2383.     {
  2384.       int aggregate
  2385.     = (TREE_CODE (TREE_TYPE (parm)) == ARRAY_TYPE
  2386.        || TREE_CODE (TREE_TYPE (parm)) == RECORD_TYPE
  2387.        || TREE_CODE (TREE_TYPE (parm)) == UNION_TYPE);
  2388.       struct args_size stack_offset;
  2389.       rtx stack_offset_rtx;
  2390.       enum direction where_pad;
  2391.  
  2392.       DECL_OFFSET (parm) = -1;
  2393.  
  2394.       if (TREE_TYPE (parm) == error_mark_node)
  2395.     {
  2396.       DECL_RTL (parm) = gen_rtx (MEM, BLKmode, const0_rtx);
  2397.       continue;
  2398.     }
  2399.  
  2400.       /* Find mode of arg as it is passed, and mode of arg
  2401.      as it should be during execution of this function.  */
  2402.       passed_mode = TYPE_MODE (DECL_ARG_TYPE (parm));
  2403.       nominal_mode = TYPE_MODE (TREE_TYPE (parm));
  2404.  
  2405.       /* Get this parm's offset as an rtx.  */
  2406.       stack_offset = stack_args_size;
  2407.       stack_offset.constant += FIRST_PARM_OFFSET;
  2408.  
  2409.       /* Find out if the parm needs padding, and whether above or below.  */
  2410.       where_pad
  2411.     = FUNCTION_ARG_PADDING (passed_mode,
  2412.                 expand_expr (size_in_bytes (DECL_ARG_TYPE (parm)),
  2413.                          0, VOIDmode, 0));
  2414.  
  2415.       /* If it is padded below, adjust the stack address
  2416.      upward over the padding.  */
  2417.       if (where_pad == downward)
  2418.     {
  2419.       if (passed_mode != BLKmode)
  2420.         {
  2421.           if (GET_MODE_BITSIZE (passed_mode) % PARM_BOUNDARY)
  2422.         stack_offset.constant
  2423.           += (((GET_MODE_BITSIZE (passed_mode) + PARM_BOUNDARY - 1)
  2424.                / PARM_BOUNDARY * PARM_BOUNDARY / BITS_PER_UNIT)
  2425.               - GET_MODE_SIZE (passed_mode));
  2426.         }
  2427.       else
  2428.         {
  2429.           tree sizetree = size_in_bytes (DECL_ARG_TYPE (parm));
  2430.           /* Round the size up to multiple of PARM_BOUNDARY bits.  */
  2431.           tree s1 = convert_units (sizetree, BITS_PER_UNIT, PARM_BOUNDARY);
  2432.           tree s2 = convert_units (s1, PARM_BOUNDARY, BITS_PER_UNIT);
  2433.           /* Add it in.  */
  2434.           ADD_PARM_SIZE (stack_offset, s2);
  2435.           SUB_PARM_SIZE (stack_offset, sizetree);
  2436.         }
  2437.     }
  2438.  
  2439.       stack_offset_rtx = ARGS_SIZE_RTX (stack_offset);
  2440.  
  2441.       /* Determine parm's home in the stack,
  2442.      in case it arrives in the stack or we should pretend it did.  */
  2443.       stack_parm
  2444.     = gen_rtx (MEM, passed_mode,
  2445.            memory_address (passed_mode,
  2446.                    gen_rtx (PLUS, Pmode,
  2447.                         arg_pointer_rtx, stack_offset_rtx)));
  2448.  
  2449.       /* If this is a memory ref that contains aggregate components,
  2450.      mark it as such for cse and loop optimize.  */
  2451.       stack_parm->in_struct = aggregate;
  2452.  
  2453.       /* Let machine desc say which reg (if any) the parm arrives in.
  2454.      0 means it arrives on the stack.  */
  2455.       entry_parm = 0;
  2456.       /* Variable-size args, and args following such, are never in regs.  */
  2457.       if (TREE_CODE (TYPE_SIZE (TREE_TYPE (parm))) == INTEGER_CST
  2458.       || stack_offset.var != 0)
  2459.     {
  2460. #ifdef FUNCTION_INCOMING_ARG
  2461.       entry_parm
  2462.         = FUNCTION_INCOMING_ARG (args_so_far, passed_mode,
  2463.                      DECL_ARG_TYPE (parm), 1);
  2464. #else
  2465.       entry_parm
  2466.         = FUNCTION_ARG (args_so_far, passed_mode, DECL_ARG_TYPE (parm), 1);
  2467. #endif
  2468.     }
  2469.       /* If this parm was passed part in regs and part in memory,
  2470.      pretend it arrived entirely in memory
  2471.      by pushing the register-part onto the stack.
  2472.  
  2473.      In the special case of a DImode or DFmode that is split,
  2474.      we could put it together in a pseudoreg directly,
  2475.      but for now that's not worth bothering with.  */
  2476.  
  2477.       /* If this is the last named arg and anonymous args follow,
  2478.      likewise pretend this arg arrived on the stack
  2479.      so varargs can find the anonymous args following it.  */
  2480.       {
  2481.     int nregs = 0;
  2482.     int i;
  2483. #ifdef FUNCTION_ARG_PARTIAL_NREGS
  2484.     nregs = FUNCTION_ARG_PARTIAL_NREGS (args_so_far, passed_mode,
  2485.                         DECL_ARG_TYPE (parm), 1);
  2486. #endif
  2487.     if (TREE_CHAIN (parm) == 0 && vararg && entry_parm != 0)
  2488.       {
  2489.         if (GET_MODE (entry_parm) == BLKmode)
  2490.           nregs = GET_MODE_SIZE (GET_MODE (entry_parm)) / UNITS_PER_WORD;
  2491.         else
  2492.           nregs = (int_size_in_bytes (DECL_ARG_TYPE (parm))
  2493.                / UNITS_PER_WORD);
  2494.       }
  2495.  
  2496.     if (nregs > 0)
  2497.       {
  2498.         current_function_pretend_args_size
  2499.           = (((nregs * UNITS_PER_WORD) + (PARM_BOUNDARY / BITS_PER_UNIT) - 1)
  2500.          / (PARM_BOUNDARY / BITS_PER_UNIT)
  2501.          * (PARM_BOUNDARY / BITS_PER_UNIT));
  2502.  
  2503.         i = nregs;
  2504.         while (--i >= 0)
  2505.           emit_move_insn (gen_rtx (MEM, SImode,
  2506.                        plus_constant (XEXP (stack_parm, 0),
  2507.                               i * GET_MODE_SIZE (SImode))),
  2508.                   gen_rtx (REG, SImode, REGNO (entry_parm) + i));
  2509.         entry_parm = stack_parm;
  2510.       }
  2511.       }
  2512.  
  2513.       /* If we didn't decide this parm came in a register,
  2514.      by default it came on the stack.  */
  2515.       if (entry_parm == 0)
  2516.     entry_parm = stack_parm;
  2517.  
  2518.       /* For a stack parm, record in DECL_OFFSET the arglist offset
  2519.      of the parm at the time it is passed (before conversion).  */
  2520.       if (entry_parm == stack_parm)
  2521.     DECL_OFFSET (parm) = stack_offset.constant * BITS_PER_UNIT;
  2522.  
  2523.       /* If there is actually space on the stack for this parm,
  2524.      count it in stack_args_size; otherwise set stack_parm to 0
  2525.      to indicate there is no preallocated stack slot for the parm.  */
  2526.  
  2527.       if (entry_parm == stack_parm
  2528. #ifdef REG_PARM_STACK_SPACE
  2529.       /* On some machines, even if a parm value arrives in a register
  2530.          there is still an (uninitialized) stack slot allocated for it.  */
  2531.       || 1
  2532. #endif
  2533.       )
  2534.     {
  2535.       tree sizetree = size_in_bytes (DECL_ARG_TYPE (parm));
  2536.       if (where_pad != none)
  2537.         {
  2538.           /* Round the size up to multiple of PARM_BOUNDARY bits.  */
  2539.           tree s1 = convert_units (sizetree, BITS_PER_UNIT, PARM_BOUNDARY);
  2540.           sizetree = convert_units (s1, PARM_BOUNDARY, BITS_PER_UNIT);
  2541.         }
  2542.       /* Add it in.  */
  2543.       ADD_PARM_SIZE (stack_args_size, sizetree);
  2544.     }
  2545.       else
  2546.     /* No stack slot was pushed for this parm.  */
  2547.     stack_parm = 0;
  2548.  
  2549.       /* Now adjust STACK_PARM to the mode and precise location
  2550.      where this parameter should live during execution,
  2551.      if we discover that it must live in the stack during execution.
  2552.      To make debuggers happier on big-endian machines, we store
  2553.      the value in the last bytes of the space available.  */
  2554.  
  2555.       if (nominal_mode != BLKmode && nominal_mode != passed_mode
  2556.       && stack_parm != 0)
  2557.     {
  2558. #ifdef BYTES_BIG_ENDIAN
  2559.       if (GET_MODE_SIZE (nominal_mode) < UNITS_PER_WORD)
  2560.         {
  2561.           stack_offset.constant
  2562.         += GET_MODE_SIZE (passed_mode)
  2563.           - GET_MODE_SIZE (nominal_mode);
  2564.           stack_offset_rtx = ARGS_SIZE_RTX (stack_offset);
  2565.         }
  2566. #endif
  2567.  
  2568.       stack_parm
  2569.         = gen_rtx (MEM, nominal_mode,
  2570.                memory_address (nominal_mode,
  2571.                        gen_rtx (PLUS, Pmode,
  2572.                         arg_pointer_rtx,
  2573.                         stack_offset_rtx)));
  2574.  
  2575.       /* If this is a memory ref that contains aggregate components,
  2576.          mark it as such for cse and loop optimize.  */
  2577.       stack_parm->in_struct = aggregate;
  2578.     }
  2579.  
  2580.       /* ENTRY_PARM is an RTX for the parameter as it arrives,
  2581.      in the mode in which it arrives.
  2582.      STACK_PARM is an RTX for a stack slot where the parameter can live
  2583.      during the function (in case we want to put it there).
  2584.      STACK_PARM is 0 if no stack slot was pushed for it.
  2585.  
  2586.      Now output code if necessary to convert ENTRY_PARM to
  2587.      the type in which this function declares it,
  2588.      and store that result in an appropriate place,
  2589.      which may be a pseudo reg, may be STACK_PARM,
  2590.      or may be a local stack slot if STACK_PARM is 0.
  2591.  
  2592.      Set DECL_RTL to that place.  */
  2593.  
  2594.       if (nominal_mode == BLKmode)
  2595.     {
  2596.       /* If a BLKmode arrives in registers, copy it to a stack slot.  */
  2597.       if (GET_CODE (entry_parm) == REG)
  2598.         {
  2599.           if (stack_parm == 0)
  2600.         stack_parm
  2601.           = assign_stack_local (GET_MODE (entry_parm),
  2602.                     int_size_in_bytes (TREE_TYPE (parm)));
  2603.  
  2604.           move_block_from_reg (REGNO (entry_parm), stack_parm,
  2605.                    int_size_in_bytes (TREE_TYPE (parm))
  2606.                    / UNITS_PER_WORD);
  2607.         }
  2608.       DECL_RTL (parm) = stack_parm;
  2609.     }
  2610.       else if (! ((obey_regdecls && ! TREE_REGDECL (parm))
  2611.           /* If -ffloat-store specified, don't put explicit
  2612.              float variables into registers.  */
  2613.           || (flag_float_store
  2614.               && TREE_CODE (TREE_TYPE (parm)) == REAL_TYPE)))
  2615.     {
  2616.       /* Store the parm in a pseudoregister during the function.  */
  2617.       register rtx parmreg = gen_reg_rtx (nominal_mode);
  2618.  
  2619.       parmreg->volatil = 1;
  2620.       DECL_RTL (parm) = parmreg;
  2621.  
  2622.       /* Copy the value into the register.  */
  2623.       if (GET_MODE (parmreg) != GET_MODE (entry_parm))
  2624.         convert_move (parmreg, entry_parm, 0);
  2625.       else
  2626.         emit_move_insn (parmreg, entry_parm);
  2627.  
  2628.       /* In any case, record the parm's desired stack location
  2629.          in case we later discover it must live in the stack.  */
  2630.       if (REGNO (parmreg) >= nparmregs)
  2631.         {
  2632.           rtx *new;
  2633.           nparmregs = REGNO (parmreg) + 5;
  2634.           new = (rtx *) oballoc (nparmregs * sizeof (rtx));
  2635.           bcopy (parm_reg_stack_loc, new, nparmregs * sizeof (rtx));
  2636.           parm_reg_stack_loc = new;
  2637.         }
  2638.       parm_reg_stack_loc[REGNO (parmreg)] = stack_parm;
  2639.  
  2640.       /* Mark the register as eliminable if we did no conversion
  2641.          and it was copied from memory at a fixed offset.  */
  2642.       if (nominal_mode == passed_mode
  2643.           && GET_CODE (entry_parm) == MEM
  2644.           && stack_offset.var == 0)
  2645.         REG_NOTES (get_last_insn ()) = gen_rtx (EXPR_LIST, REG_EQUIV,
  2646.                             entry_parm, 0);
  2647.  
  2648.       /* For pointer data type, suggest pointer register.  */
  2649.       if (TREE_CODE (TREE_TYPE (parm)) == POINTER_TYPE)
  2650.         mark_reg_pointer (parmreg);
  2651.     }
  2652.       else
  2653.     {
  2654.       /* Value must be stored in the stack slot STACK_PARM
  2655.          during function execution.  */
  2656.  
  2657.       if (passed_mode != nominal_mode)
  2658.         /* Conversion is required.  */
  2659.         entry_parm = convert_to_mode (nominal_mode, entry_parm, 0);
  2660.  
  2661.       if (entry_parm != stack_parm)
  2662.         {
  2663.           if (stack_parm == 0)
  2664.         stack_parm = assign_stack_local (GET_MODE (entry_parm),
  2665.                          GET_MODE_SIZE (GET_MODE (entry_parm)));
  2666.           emit_move_insn (stack_parm, entry_parm);
  2667.         }
  2668.  
  2669.       DECL_RTL (parm) = stack_parm;
  2670.       frame_pointer_needed = 1;
  2671.     }
  2672.       
  2673.       if (TREE_VOLATILE (parm))
  2674.     DECL_RTL (parm)->volatil = 1;
  2675.       if (TREE_READONLY (parm))
  2676.     DECL_RTL (parm)->unchanging = 1;
  2677.  
  2678.       /* Update info on where next arg arrives in registers.  */
  2679.  
  2680.       FUNCTION_ARG_ADVANCE (args_so_far, passed_mode, DECL_ARG_TYPE (parm), 1);
  2681.     }
  2682.  
  2683.   max_parm_reg = max_reg_num ();
  2684.   last_parm_insn = get_last_insn ();
  2685.  
  2686.   current_function_args_size = stack_args_size.constant;
  2687. }
  2688.  
  2689. /* Allocation of space for returned structure values.
  2690.    During the rtl generation pass, `get_structure_value_addr'
  2691.    is called from time to time to request the address of a block in our
  2692.    stack frame in which called functions will store the structures
  2693.    they are returning.  The same space is used for all of these blocks.  
  2694.  
  2695.    We allocate these blocks like stack locals.  We keep reusing
  2696.    the same block until a bigger one is needed.  */
  2697.  
  2698. /* Length in bytes of largest structure value returned by
  2699.    any function called so far in this function.  */
  2700. static int max_structure_value_size;
  2701.  
  2702. /* An rtx for the addr we are currently using for structure values.
  2703.    This is typically (PLUS (REG:SI stackptr) (CONST_INT...)).  */
  2704. static rtx structure_value;
  2705.  
  2706. rtx
  2707. get_structure_value_addr (sizex)
  2708.      rtx sizex;
  2709. {
  2710.   register int size;
  2711.   if (GET_CODE (sizex) != CONST_INT)
  2712.     abort ();
  2713.   size = INTVAL (sizex);
  2714.  
  2715.   /* Round up to a multiple of the main allocation unit.  */
  2716.   size = (((size + (BIGGEST_ALIGNMENT / BITS_PER_UNIT) - 1)
  2717.        / (BIGGEST_ALIGNMENT / BITS_PER_UNIT))
  2718.       * (BIGGEST_ALIGNMENT / BITS_PER_UNIT));
  2719.  
  2720.   /* If this size is bigger than space we know to use,
  2721.      get a bigger piece of space.  */
  2722.   if (size > max_structure_value_size)
  2723.     {
  2724.       max_structure_value_size = size;
  2725.       structure_value = assign_stack_local (BLKmode, size);
  2726.       if (GET_CODE (structure_value) == MEM)
  2727.     structure_value = XEXP (structure_value, 0);
  2728.     }
  2729.  
  2730.   return structure_value;
  2731. }
  2732.  
  2733. /* Walk the tree of LET_STMTs describing the binding levels within a function
  2734.    and warn about uninitialized variables.
  2735.    This is done after calling flow_analysis and before global_alloc
  2736.    clobbers the pseudo-regs to hard regs.  */
  2737.  
  2738. void
  2739. uninitialized_vars_warning (block)
  2740.      tree block;
  2741. {
  2742.   register tree decl, sub;
  2743.   for (decl = STMT_VARS (block); decl; decl = TREE_CHAIN (decl))
  2744.     {
  2745.       if (TREE_CODE (decl) == VAR_DECL
  2746.       /* These warnings are unreliable for and aggregates
  2747.          because assigning the fields one by one can fail to convince
  2748.          flow.c that the entire aggregate was initialized.
  2749.          Unions are troublesome because members may be shorter.  */
  2750.       && TREE_CODE (TREE_TYPE (decl)) != RECORD_TYPE
  2751.       && TREE_CODE (TREE_TYPE (decl)) != UNION_TYPE
  2752.       && TREE_CODE (TREE_TYPE (decl)) != ARRAY_TYPE
  2753.       && GET_CODE (DECL_RTL (decl)) == REG
  2754.       && regno_uninitialized (REGNO (DECL_RTL (decl))))
  2755.     warning_with_decl (decl,
  2756.                "variable `%s' used uninitialized in this function");
  2757.       if (TREE_CODE (decl) == VAR_DECL
  2758.       && GET_CODE (DECL_RTL (decl)) == REG
  2759.       && regno_clobbered_at_setjmp (REGNO (DECL_RTL (decl))))
  2760.     warning_with_decl (decl,
  2761.                "variable `%s' may be clobbered by `longjmp'");
  2762.     }
  2763.   for (sub = STMT_BODY (block); sub; sub = TREE_CHAIN (sub))
  2764.     uninitialized_vars_warning (sub);
  2765. }
  2766.  
  2767. /* Generate RTL for the start of the function FUNC (a FUNCTION_DECL tree node)
  2768.    and initialize static variables for generating RTL for the statements
  2769.    of the function.  */
  2770.  
  2771. void
  2772. expand_function_start (subr)
  2773.      tree subr;
  2774. {
  2775.   register int i;
  2776.   tree tem;
  2777.  
  2778.   this_function = subr;
  2779.   cse_not_expected = ! optimize;
  2780.  
  2781.   /* We have not yet found a reason why a frame pointer cannot
  2782.      be omitted for this function in particular, but maybe we know
  2783.      a priori that it is required.
  2784.      `flag_omit_frame_pointer' has its main effect here.  */
  2785.   frame_pointer_needed = FRAME_POINTER_REQUIRED || ! flag_omit_frame_pointer;
  2786.  
  2787.   /* No gotos have been expanded yet.  */
  2788.   goto_fixup_chain = 0;
  2789.  
  2790.   /* No invalid stack slots have been made yet.  */
  2791.   invalid_stack_slot = 0;
  2792.  
  2793.   /* Initialize the RTL mechanism.  */
  2794.   init_emit (write_symbols);
  2795.  
  2796.   /* Initialize the queue of pending postincrement and postdecrements,
  2797.      and some other info in expr.c.  */
  2798.   init_expr ();
  2799.  
  2800.   init_const_rtx_hash_table ();
  2801.  
  2802.   /* Decide whether function should try to pop its args on return.  */
  2803.  
  2804.   current_function_pops_args = RETURN_POPS_ARGS (TREE_TYPE (subr));
  2805.  
  2806.   current_function_name = IDENTIFIER_POINTER (DECL_NAME (subr));
  2807.  
  2808.   /* Make the label for return statements to jump to, if this machine
  2809.      does not have a one-instruction return.  */
  2810. #ifdef FUNCTION_EPILOGUE
  2811.   return_label = gen_label_rtx ();
  2812. #else
  2813.   return_label = 0;
  2814. #endif
  2815.  
  2816.   /* No space assigned yet for structure values.  */
  2817.   max_structure_value_size = 0;
  2818.   structure_value = 0;
  2819.  
  2820.   /* We are not currently within any block, conditional, loop or case.  */
  2821.   block_stack = 0;
  2822.   loop_stack = 0;
  2823.   case_stack = 0;
  2824.   cond_stack = 0;
  2825.   nesting_stack = 0;
  2826.   nesting_depth = 0;
  2827.  
  2828.   /* We have not yet needed to make a label to jump to for tail-recursion.  */
  2829.   tail_recursion_label = 0;
  2830.  
  2831.   /* No stack slots allocated yet.  */
  2832.   frame_offset = STARTING_FRAME_OFFSET;
  2833.  
  2834.   /* No SAVE_EXPRs in this function yet.  */
  2835.   save_expr_regs = 0;
  2836.  
  2837.   /* Within function body, compute a type's size as soon it is laid out.  */
  2838.   immediate_size_expand++;
  2839.  
  2840.   init_pending_stack_adjust ();
  2841.   clear_current_args_size ();
  2842.  
  2843.   /* Prevent ever trying to delete the first instruction of a function.
  2844.      Also tell final how to output a linenum before the function prologue.  */
  2845.   emit_note (DECL_SOURCE_FILE (subr), DECL_SOURCE_LINE (subr));
  2846.   /* Make sure first insn is a note even if we don't want linenums.
  2847.      This makes sure the first insn will never be deleted.
  2848.      Also, final expects a note to appear there.  */
  2849.   emit_note (0, NOTE_INSN_DELETED);
  2850.  
  2851.   /* Initialize rtx for parameters and local variables.
  2852.      In some cases this requires emitting insns.  */
  2853.  
  2854.   assign_parms (subr);
  2855.  
  2856.   /* If doing stupid allocation, mark parms as born here.  */
  2857.  
  2858.   if (obey_regdecls)
  2859.     {
  2860.       parm_birth_insn = get_last_insn ();
  2861.       for (i = FIRST_PSEUDO_REGISTER; i < max_parm_reg; i++)
  2862.     use_variable (regno_reg_rtx[i]);
  2863.     }
  2864.  
  2865.   /* After the parm initializations is where the tail-recursion label
  2866.      should go, if we end up needing one.  */
  2867.   tail_recursion_reentry = get_last_insn ();
  2868.  
  2869.   /* Evaluate now the sizes of any types declared among the arguments.  */
  2870.   for (tem = get_pending_sizes (); tem; tem = TREE_CHAIN (tem))
  2871.     expand_expr (TREE_VALUE (tem), 0, VOIDmode, 0);
  2872.  
  2873.   /* Initialize rtx used to return the value.  */
  2874.  
  2875.   if (DECL_MODE (DECL_RESULT (subr)) == BLKmode)
  2876.     {
  2877.       /* Returning something that won't go in a register.  */
  2878.       register rtx value_address;
  2879.  
  2880.       /* Expect to be passed the address of a place to store the value.  */
  2881.       value_address = gen_reg_rtx (Pmode);
  2882.       emit_move_insn (value_address, struct_value_incoming_rtx);
  2883.       DECL_RTL (DECL_RESULT (subr))
  2884.     = gen_rtx (MEM, DECL_MODE (DECL_RESULT (subr)),
  2885.            value_address);
  2886.     }
  2887.   else
  2888. #ifdef FUNCTION_OUTGOING_VALUE
  2889.     DECL_RTL (DECL_RESULT (subr))
  2890.       = FUNCTION_OUTGOING_VALUE (TREE_TYPE (DECL_RESULT (subr)), subr);
  2891. #else
  2892.     DECL_RTL (DECL_RESULT (subr))
  2893.       = FUNCTION_VALUE (TREE_TYPE (DECL_RESULT (subr)), subr);
  2894. #endif
  2895.  
  2896.   /* Mark this reg as the function's return value.  */
  2897.   if (GET_CODE (DECL_RTL (DECL_RESULT (subr))) == REG)
  2898.     REG_FUNCTION_VALUE_P (DECL_RTL (DECL_RESULT (subr))) = 1;
  2899. }
  2900.  
  2901. /* Generate RTL for the end of the current function.
  2902.    LINE is the line number.  */
  2903.  
  2904. void
  2905. expand_function_end (filename, line)
  2906.      char *filename;
  2907.      int line;
  2908. {
  2909.   register int i;
  2910.  
  2911.   /* Outside function body, can't compute type's actual size
  2912.      until next function's body starts.  */
  2913.   immediate_size_expand--;
  2914.  
  2915.   /* If doing stupid register allocation,
  2916.      mark register parms as dying here.  */
  2917.  
  2918.   if (obey_regdecls)
  2919.     {
  2920.       rtx tem;
  2921.       for (i = FIRST_PSEUDO_REGISTER; i < max_parm_reg; i++)
  2922.     use_variable (regno_reg_rtx[i]);
  2923.  
  2924.       /* Likewise for the regs of all the SAVE_EXPRs in the function.  */
  2925.  
  2926.       for (tem = save_expr_regs; tem; tem = XEXP (tem, 1))
  2927.     emit_insn (gen_rtx (USE, VOIDmode, XEXP (tem, 0)));
  2928.  
  2929.       /* Also mark those as borm at the beginning of the function.
  2930.      (This was done in expand_function_start for parms).  */
  2931.       for (tem = save_expr_regs; tem; tem = XEXP (tem, 1))
  2932.     emit_insn_after (gen_rtx (USE, VOIDmode, XEXP (tem, 0)),
  2933.              parm_birth_insn);
  2934.     }
  2935.  
  2936.   clear_pending_stack_adjust ();
  2937.   do_pending_stack_adjust ();
  2938.  
  2939.   /* Mark the end of the function body.
  2940.      If control reaches this insn, the function can drop through
  2941.      without returning a value.  */
  2942.   emit_note (0, NOTE_INSN_FUNCTION_END);
  2943.  
  2944.   /* Output a linenumber for the end of the function.
  2945.      SDB depends on this.  */
  2946.   emit_note (input_filename, line);
  2947.  
  2948.   /* If we require a true epilogue,
  2949.      put here the label that return statements jump to.
  2950.      If there will be no epilogue, write a return instruction.  */
  2951. #ifdef FUNCTION_EPILOGUE
  2952.   emit_label (return_label);
  2953. #else
  2954.   emit_jump_insn (gen_return ());
  2955. #endif
  2956.  
  2957.   /* Fix up any gotos that jumped out to the outermost
  2958.      binding level of the function.
  2959.      Must follow emitting RETURN_LABEL.  */
  2960.   fixup_gotos (0, get_insns ());
  2961. }
  2962.  
  2963.  
  2964.